+ Reply to Thread
Results 1 to 12 of 12

Generate Random Numbers Between 0-9

  1. #1
    Forum Contributor
    Join Date
    04-02-2008
    Location
    Jacksonville Beach, Florida
    MS-Off Ver
    Microsoft Excel 2003 and 2010
    Posts
    264

    Generate Random Numbers Between 0-9

    I am trying to generate random numbers between 0 - 9 in ten cells that do not repeat an always include every value 0 - 9 (0, 1, 2, 3, 4,...9). The object is to have the numbers randomize each time. So cells A1:A10 could look like this:

    3
    9
    4
    5
    1
    0
    6
    8
    7
    2

    Or, they could look like this:

    9
    7
    5
    2
    8
    4
    1
    3
    6
    0

    I understand the rand and randbetween formulas, but am having trouble finding the logic to make them non-repeating, all inclusive and still random.

    Any help? A bonus point for anyone who can figure out what this is for (hint: there is a kick-off in about four hours).
    Last edited by dreicer_Jarr; 02-02-2009 at 08:52 PM. Reason: Now Solved

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Generate Random Numbers Between 0-9

    Hi,

    Probably the easiest way is to list your numbers 0-9 in one column and alongside each of them in another column put the formula:

    Please Login or Register  to view this content.
    Now just sort the two columns using the random number as the key.

    You could achieve the same sort of thing with a macro if you didn't want to see the 'workings'

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Generate Random Numbers Between 0-9

    I would use RAND rather than RANDBETWEEN in the sort key column.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Generate Random Numbers Between 0-9

    dreicer_Jarr,

    FYI

    Richard forget to mention you need to install the Analysis ToolPak add-in before you can use Randbewteen.

    Edit

    Unless you have xl07

    VBA Noob
    Last edited by VBA Noob; 02-01-2009 at 03:55 PM.
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

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

    Re: Generate Random Numbers Between 0-9

    I presume this is related to something called "The Superbowl", whatever that is.......

    This is one way to achieve what you want without helper cells.....

    In A1

    =INT(RAND()*10)

    in A2

    =SMALL(IF(ISNA(MATCH({0,1,2,3,4,5,6,7,8,9},A$1:A1,0)),{0,1,2,3,4,5,6,7,8,9}),INT(RAND()*(10-ROWS(A$2:A2))+1))

    confirmed with CTRL+SHIFT+ENTER and copied down to A10

  6. #6
    Registered User
    Join Date
    11-29-2012
    Location
    Arizona
    MS-Off Ver
    Excel 2011
    Posts
    3

    Re: Generate Random Numbers Between 0-9

    Quote Originally Posted by daddylonglegs View Post
    I presume this is related to something called "The Superbowl", whatever that is.......

    This is one way to achieve what you want without helper cells.....

    In A1

    =INT(RAND()*10)

    in A2

    =SMALL(IF(ISNA(MATCH({0,1,2,3,4,5,6,7,8,9},A$1:A1,0)),{0,1,2,3,4,5,6,7,8,9}),INT(RAND()*(10-ROWS(A$2:A2))+1))

    confirmed with CTRL+SHIFT+ENTER and copied down to A10
    I was able to use this formula for the rows going down the side, but when I tried to change it for the columns going across the top, numbers kept repeating. Any suggestions?

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

    Re: Generate Random Numbers Between 0-9

    The ROWS part increments when you copy down, if you want to copy across you need COLUMNS and the $ signs get adjusted, so this version in B1 copied across

    =SMALL(IF(ISNA(MATCH({0,1,2,3,4,5,6,7,8,9},$A1:A1,0)),{0,1,2,3,4,5,6,7,8,9}),INT(RAND()*(10-COLUMNS($B1:B1))+1))
    Audere est facere

  8. #8
    Registered User
    Join Date
    11-29-2012
    Location
    Arizona
    MS-Off Ver
    Excel 2011
    Posts
    3

    Re: Generate Random Numbers Between 0-9

    I used =SMALL(IF(ISNA(MATCH({0,1,2,3,4,5,6,7,8,9},A$2:A2,0)),{0,1,2,3,4,5,6,7,8,9}),INT(RAND()*(10-ROWS(A$3:A3))+1)) because A1 isn't assigned for either the ROWS or COLUMNS.

    I used =SMALL(IF(ISNA(MATCH({0,1,2,3,4,5,6,7,8,9},B$1:B1,0)),{0,1,2,3,4,5,6,7,8,9}),INT(RAND()*(10-COLUMNS(C$1:C1))+1)), but it keeps giving me repeated numbers. Also, I used =INT(RAND()*10) for both A2 and B1. Did I enter something wrong?

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

    Re: Generate Random Numbers Between 0-9

    You didn't switch the $ symbols - when copying down you have B$1:B1 but for copying across it's $B1:B1 so in C1 you need this formula

    =SMALL(IF(ISNA(MATCH({0,1,2,3,4,5,6,7,8,9},$B1:B1,0)),{0,1,2,3,4,5,6,7,8,9}),INT(RAND()*(10-COLUMNS($C1:C1))+1))

    confirm with CTRL+SHIFT+ENTER and copy across

  10. #10
    Registered User
    Join Date
    11-29-2012
    Location
    Arizona
    MS-Off Ver
    Excel 2011
    Posts
    3

    Re: Generate Random Numbers Between 0-9

    Thank you! I would have never caught that.

  11. #11
    Registered User
    Join Date
    01-16-2014
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Generate Random Numbers Between 0-9

    This thread has been extremely helpful. I just have one question about generating random numbers going down the rows and not across the columns. Specifically I need to generate a random non-repeating number from 1-10 that will be paired with numbers 1-10.

    For example:
    A B
    1 1
    2 2
    3 3
    4 4
    5 5
    6 6
    7 7
    8 8
    9 9
    10 10

    Each number in Column A is a fixed location (in my case nest a bird fledged from), column B is the location of it's first adult nest one year later. What I would like to do is repeat the numbers is column A 1-10, 1-10 (no problem) and so on, but each time generate a random non-repeating number in column B for each set of ten numbers in column A.

    In the example above, I could do this by doing a lot of copying and pasting so I'm wondering if anyone knows a way to do it like I need.

    Thanks, Dan

  12. #12
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Generate Random Numbers Between 0-9

    Dan Small,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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