+ Reply to Thread
Results 1 to 14 of 14

Help using RANDBETWEEN

  1. #1
    Registered User
    Join Date
    07-31-2009
    Location
    Venezuela
    MS-Off Ver
    Excel 2003
    Posts
    5

    Help using RANDBETWEEN

    Hello all.

    I'm using the RANDBETWEEN(1,15) excel function to fill a range of cells with random numbers between 1 and 15, the problem is that each cell cannot be the same number than any other in that range, how exactly can i accomplish this?

    I attached a file for a better example, if you hit F9 you can see that sometimes at least 2 cells share the same number...but I need it to be different on each one, and still be random.

    Any tip or help would be very apreciated.

    Thank you in advance.
    Attached Files Attached Files
    Last edited by retghy; 08-02-2009 at 10:51 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help using RANDBETWEEN

    This is one way to insure duplicates don't happen.
    Attached Files Attached Files
    Last edited by JBeaucaire; 07-31-2009 at 03:15 AM. Reason: Added more comments into sheet sample
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Help using RANDBETWEEN

    If you run a search on the board of Unique Random Numbers I think you will find a few posts.

    One nice little approach that doesn't require too much thinking is to use helpers, using your sample file for example:

    F4: =ROWS(F$4:F4)
    copied to F18 ... thereby generating 1 to 15

    G4: =RAND()
    copied to G18

    You can then retrieve 1-15 randomly based on the RAND value in G, say pulling associated value based on RAND LARGE 1 to LARGE 9

    D4: =INDEX($F$4:$F$18,MATCH(LARGE($G$4:$G$18,ROWS(D$4:D4)),$G$4:$G$18,0))
    copied down to D12


    EDIT: above is identical approach to JB... quick this eve. (?) JB

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Help using RANDBETWEEN

    Without using a helper column......you could use this formula in D4 copied down

    =SMALL(IF(COUNTIF(D$3:D3,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}),"", {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}),INT(RAND()*(15-ROWS(D$4:D4)+1))+1)

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Help using RANDBETWEEN

    ...and for a helper column approach....you can use this formula in C4 copied to C18

    =RAND()

    and then in D4 copied down

    =RANK(C4,C$4:C$18)

  6. #6
    Registered User
    Join Date
    07-31-2009
    Location
    Venezuela
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Help using RANDBETWEEN

    Thank you for your quick answers, I'm on my way to work, can't wait to try your solutions. I'll let you know how it goes.

    Last nigth I was trying using an IF statement (if number is equal than cell above generate another) but no luck, I see you got a different approach.

    Thanks again.

  7. #7
    Registered User
    Join Date
    07-31-2009
    Location
    Venezuela
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Help using RANDBETWEEN

    Quote Originally Posted by daddylonglegs View Post
    Without using a helper column......you could use this formula in D4 copied down

    =SMALL(IF(COUNTIF(D$3:D3,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}),"", {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}),INT(RAND()*(15-ROWS(D$4:D4)+1))+1)
    I couldn't make it work using that formula, maybe because my office suite is in spanish and I picked the wrong function.

    The helpper method worked great, thank you!

    With all this a was trying to make 50 columns and none can be equal and the thing with it is that when you apply the same formulas to another colum you get the same results of course.

    Do I have to create another helper page for every column I need?
    Last edited by retghy; 08-02-2009 at 03:08 AM.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Help using RANDBETWEEN

    I couldn't make it work using that formula, maybe because my office suite is in spanish and I picked the wrong function.
    I believe in Spanish this:

    Please Login or Register  to view this content.
    would perhaps become the below in terms of delimiter syntax:

    Please Login or Register  to view this content.
    or if functions are also in Spanish perhaps:

    Please Login or Register  to view this content.

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Help using RANDBETWEEN

    muy bueno ,Don Quixote lol
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Help using RANDBETWEEN

    de nada ...

  11. #11
    Registered User
    Join Date
    07-31-2009
    Location
    Venezuela
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Help using RANDBETWEEN

    Quote Originally Posted by DonkeyOte View Post
    I believe in Spanish this:

    Please Login or Register  to view this content.
    would perhaps become the below in terms of delimiter syntax:

    Please Login or Register  to view this content.
    or if functions are also in Spanish perhaps:

    Please Login or Register  to view this content.
    Muy agradecido por su ayuda.

    It works without the helpers, but sadly you still get duplicates in the column.

  12. #12
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Help using RANDBETWEEN

    Quote Originally Posted by retghy View Post
    Muy agradecido por su ayuda.

    It works without the helpers, but sadly you still get duplicates in the column.
    You shouldn't get duplicates. Here's an example using your original......
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    07-31-2009
    Location
    Venezuela
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Help using RANDBETWEEN

    Quote Originally Posted by daddylonglegs View Post
    You shouldn't get duplicates. Here's an example using your original......
    In your example I don't get any duplicate your right, maybe it was something with my function.

    Thank you all for the tips and help, you've been very supportive.

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help using RANDBETWEEN

    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in the posts to leave Reputation Feedback, it is appreciated)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1