+ Reply to Thread
Results 1 to 8 of 8

Generate a random set of numbers without duplicates

  1. #1
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Generate a random set of numbers without duplicates

    I have a dis-contiguous set of cells such as B4:E5, B8:E13, B17:B18, and B27:E27. 44 cells in total.

    What I'm trying to do is generate a name from a list in column G. There are 52 items in the list, but I only need to randomly generate 44 unique names.

    I've messed around with Rand() and MRAND() from the MoreFunc, but can't seem to find the right solution.

    Any thoughts?
    Attached Files Attached Files
    HTH
    Regards, Jeff

  2. #2
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Generate a random set of numbers without duplicates

    Hmm... how about assigning each cell an indexing number from 1-44, then giving each of the 52 items a number with RAND(), then assigning them arbitrarily based on the ranking of the random numbers for each item? No error handling for duplicates, just assume that RAND producing the exact same number twice is sufficiently unlikely.
    Attached Files Attached Files
    Click the [* Add Reputation] Button to thank people for help!
    Post Attachment: Click [Go Advanced] under the reply box; then click [Manage Attachments] to launch the attachments dialogue.
    Mark Thread Solved: Go to the top of the first post; Select [Thread Tools] dropdown; Pick the [Mark thread as Solved] option.

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,411

    Re: Generate a random set of numbers without duplicates

    Hi Jeff,

    you could put this in H3:

    =RAND()

    and this in I3:

    =RANK(H3,$H$3:$H$54)

    then copy down to row 54. Then you could just use an INDEX/MATCH in your group of cells to get the 1st, 2nd, 3rd etc. in sequence up to 44.

    Hope this helps.

    Pete

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Generate a random set of numbers without duplicates

    Hi Jeff,

    Try this array formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  5. #5
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Generate a random set of numbers without duplicates

    Thanks Ben, but this may not work as I would have to redesign many parts of my sheet.

    Thanks Pete. This is what I started with, but hoping I could find a solution to do the RAND() part directly in the cell. From the MoreFunc, MRAND()+1 works will, but it doesn't continue with non-contiguous cells. If I would, I can easily use, {=INDEX($G$3:$G$54,MRAND()+1)}, but can't get it to work with my configuration.

    In the end I might have to use the Rand() method.

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,411

    Re: Generate a random set of numbers without duplicates

    Well, here's the workbook. I used this in B4:

    =INDEX($G:$G,MATCH(4*COUNTA(B$3:B3)+COLUMNS($B:B),$I:$I,0))

    and copied across into C4:E4, then copied those 4 cells into the cells below with borders.

    Hope this helps.

    Pete
    Attached Files Attached Files

  7. #7
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Generate a random set of numbers without duplicates

    Hi AlKey, this seems to be generating duplicates, but Pete's non array formula just might work out fine and is not creating duplicates.

    I'll now implement this into my sheet and see how it goes.

    I do the scheduling for Sunday worship church duties and just trying to figure out a way to randomly fit names and then tailor for overlap from there.

    When I say overlap, it's because there are other duties which run off of a different rotating schedule and just playing around with the best fit versus having to manual fill out the sheet.

    Thanks everyone...

  8. #8
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,175

    Re: Generate a random set of numbers without duplicates

    Try this in B4:

    =INDEX($G:$G,SMALL(IF(COUNTIF($A4:A4,$G$3:$G$54)+COUNTIF($B$3:$E3,$G$3:$G$54)=0,ROW($G$3:$G$54)),
    RANDBETWEEN(1,52-COUNTA($A4:A4,$B$3:$E3))))

+ 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. Replies: 3
    Last Post: 09-22-2016, 09:40 AM
  2. Replies: 14
    Last Post: 09-21-2016, 05:55 AM
  3. Generate random list with no duplicates
    By imgrieve in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-25-2015, 06:48 AM
  4. Need to generate random numbers with no duplicates
    By mustbe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-27-2015, 05:32 PM
  5. [SOLVED] generate random results, removing only SOME duplicates
    By jrosko1 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-04-2013, 12:00 PM
  6. Auto-Generate random set of four numbers without duplicates?
    By adrien23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2011, 06:03 PM
  7. [SOLVED] How to generate sets of random numbers without having duplicates
    By William in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-06-2006, 12:35 AM

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