+ Reply to Thread
Results 1 to 6 of 6

How to generate random non-repeat number for a range?

  1. #1
    Forum Contributor
    Join Date
    08-20-2009
    Location
    new york
    MS-Off Ver
    Excel 2003
    Posts
    119

    How to generate random non-repeat number for a range?

    For example, I would like to assign a number to each cell of A2:A1001

    There are 1000 cells, and I would like each cell to have a non-repeat random positive integer, which is in the range of [1, 1000].

    I have to have them in random order, such as 458, 369, 567, ......, definitely not in any kinds of sorted order (1, 2, 3, 4, .....)


    Thanks.

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: How to generate random non-repeat number for a range?

    One option
    On Sheet2, in A1:A1000
    =RAND() (then copy >paste special>values so that doesn't change or change settings for this sheet to manual calcs)
    For sheet1 in A2 copied down
    =MATCH(SMALL(Sheet2!$A$1:$A$1000, ROWS($A$2:$A2), Sheet2!$A$1:$A$1000,0)
    Does that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: How to generate random non-repeat number for a range?

    If you just want to perform a random sort, perhaps this macro might help. Basically the macro is going to create a list of random number in column B and then sort Column A and Column B by column B to generate the random order.
    Attached Files Attached Files

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: How to generate random non-repeat number for a range?

    Try this array formula**:

    Entered in A2 and copied down.

    =SMALL(IF(ISNA(MATCH(ROW(INDIRECT("1:1000")),A$1:A1,0)),ROW(INDIRECT("1:1000"))),RANDBETWEEN(1,1001-ROWS(A$2:A2)))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    For 1000 rows this will be a bit slow to calculate.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,879

    Re: How to generate random non-repeat number for a range?

    here is a VBA solution also

    Option Explicit



    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  6. #6
    Forum Contributor
    Join Date
    08-20-2009
    Location
    new york
    MS-Off Ver
    Excel 2003
    Posts
    119

    Re: How to generate random non-repeat number for a range?

    Thanks, all.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Generate Random Number Wihout Repeat In One Cell
    By Kumara_faith in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-02-2015, 08:13 AM
  2. Replies: 8
    Last Post: 11-18-2013, 04:24 PM
  3. How to generate a random sample and repeat it 1000 times
    By random_Monkey in forum Excel General
    Replies: 4
    Last Post: 08-15-2013, 10:15 AM
  4. Replies: 5
    Last Post: 06-21-2013, 10:40 AM
  5. Replies: 6
    Last Post: 12-06-2012, 08:14 PM
  6. [SOLVED] How to generate a random number?
    By frankk119 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2012, 09:19 AM
  7. [SOLVED] Generate random 6-16-byte random hexadecimal number
    By jsamuelshn in forum Excel General
    Replies: 6
    Last Post: 07-20-2012, 10:38 AM
  8. generate a random number and use if function to generate new data
    By Dogdoc1142 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-25-2006, 10:50 PM

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