+ Reply to Thread
Results 1 to 6 of 6

Generate Random Numbers

  1. #1
    Registered User
    Join Date
    10-25-2007
    Posts
    85

    Generate Random Numbers

    Hey, I was wondering if there was a way to generate random numbers in a series of cells without repeating one another.

    For example, Say I want A1-D1 to be populated randomly with 1-6, not repeating a number at all. So i'd have a sequence like 132654 or 452136.

    Is that possible to do?

  2. #2
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,676
    Do you mean A1:F1.

    One way is to use this formula in A1

    =INT(RAND()*6+1)

    and then in B1 copied across to F1

    =SMALL(IF(ISNA(MATCH({1,2,3,4,5,6},$A1:A1,0)),{1,2,3,4,5,6}),INT(RAND()*(5-COLUMN()+COLUMN($B1))+1))

    confirmed with CTRL+SHIFT+ENTER

  3. #3
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,659
    The function below will enter a random sequence in whatever range it is entered. It must be entered as an array formula.

    If you don't want the sequence to change every time the sheet calculates, comment out the Application.Volatile line.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-25-2007
    Posts
    85
    Thank you both for the input, I should have mentioned that I don't want the numbers to change every time the sheet is calculated as that ends up being quite a few changes every time bogging down the system. As for the function, I saved it in the VBA editor but can't seem to call it up in the sheet itself. RandSeq(RANGE) is the proper format is it not?

  5. #5
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,676
    If you don't want the numbers to change then one option is to download the free morefunc add-in and use MRAND function. This has a setting which fixes the random numbers

  6. #6
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,659
    Quote Originally Posted by Rgaherty
    RandSeq(RANGE) is the proper format is it not?
    No, just =RandSeq(), entered as a single array formula throuhghout the range in which you want the sequence to appear.
    Quote Originally Posted by daddylonglegs
    If you don't want the numbers to change ...
    As I said, if you don't want the numbers to change, change this
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    ... or just delete the line.

+ 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