+ Reply to Thread
Results 1 to 5 of 5

Generate random numbers with no repeats

  1. #1
    Valued Forum Contributor
    Join Date
    06-30-2005
    Location
    Verwood, Dorset, England
    MS-Off Ver
    Excel 2000
    Posts
    479

    Generate random numbers with no repeats

    I want to produce a randomly generated competition draw,

    eg for 128 teams, numbered 1 to 128, what I need is a formula for cells A1 to B64, that will produce a number between 1 and 128 in each of the cells, with no repeats

    So that the team in A1 will play B1 etc

    This needs to be dynamic as the number of teams for any given competition may vary

    Thanks in advance for any help

    I have looked at rand and randbetween without success
    Paul

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Here's one possible approach.

    In E1 put the formula =RAND() and copy this down as far as you need to cover the maximum number of teams you might have, e.g. to E1000.

    In D1 enter the number of teams, e.g. 128

    In A1 use this formula

    =IF(ROW()-ROW(A$1)+1>$D$1/2,"",RANK(OFFSET($E$1,ROW()-ROW(A$1)+(COLUMN()-COLUMN($A1))*($D$1/2),),$E$1:INDEX($E$1:$E$1000,$D$1)))

    copy across to B1 and down as far as you might need.

    Assuming you have 128 in D1 then A1:B64 will now include one each of numbers 1 to 128. Subsequent cells will be blank. Change D1 to any even number to regenerate numbers. Note: recalculation of worksheet will re-generate random numbers, hide column E if you wish

  3. #3
    Valued Forum Contributor
    Join Date
    06-30-2005
    Location
    Verwood, Dorset, England
    MS-Off Ver
    Excel 2000
    Posts
    479
    Quote Originally Posted by daddylonglegs
    Here's one possible approach.

    In E1 put the formula =RAND() and copy this down as far as you need to cover the maximum number of teams you might have, e.g. to E1000.

    In D1 enter the number of teams, e.g. 128

    In A1 use this formula

    =IF(ROW()-ROW(A$1)+1>$D$1/2,"",RANK(OFFSET($E$1,ROW()-ROW(A$1)+(COLUMN()-COLUMN($A1))*($D$1/2),),$E$1:INDEX($E$1:$E$1000,$D$1)))

    copy across to B1 and down as far as you might need.

    Assuming you have 128 in D1 then A1:B64 will now include one each of numbers 1 to 128. Subsequent cells will be blank. Change D1 to any even number to regenerate numbers. Note: recalculation of worksheet will re-generate random numbers, hide column E if you wish
    Thanks daddylonglegs, that's just what I needed

  4. #4
    Registered User
    Join Date
    12-18-2006
    Posts
    46
    For future reference (and I'm talking about VBA), Rand() function does give random numbers, but starts from the same position. To avoid this, use Randomize before the Rand() function itself.

    I wrote this because this is the first thing that occured to me when I saw the title, and I suppose I won't be the only one.

    Cheers,
    Ivan.

  5. #5
    Registered User
    Join Date
    04-06-2007
    Posts
    1

    Not so random

    You might want to keep in mind that the randomness of Excel and VBA is poor and different with different versions. THis article has some details.

+ 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