Generate Random Number between 1-50 without repeats
How can I generate Random Numbers from 1050 without repeats
Apple Event: May 7th at 7 am PT
How can I generate Random Numbers from 1050 without repeats
Choose Utilities from the FInder's Go menu, open the AppleScript Editor, and run:
set the_numbers to {}
repeat until (count the_numbers) is 10 --change this number as needed; if this is greater than 50, the script won't finish
set the_num to random number from 1 to 50
if the_num is not in the_numbers then set the_numbers to the_numbers & the_num
end repeat
the_numbers
If you'd like to copy and paste the result into Numbers or another spreadsheet, add the following:
set the_string to ""
repeat with this_number in the_numbers
set the_string to the_string & this_number & return
end repeat
set the_string to items 1 thru -2 of the_string as string
(134319)
Choose Utilities from the FInder's Go menu, open the AppleScript Editor, and run:
set the_numbers to {}
repeat until (count the_numbers) is 10 --change this number as needed; if this is greater than 50, the script won't finish
set the_num to random number from 1 to 50
if the_num is not in the_numbers then set the_numbers to the_numbers & the_num
end repeat
the_numbers
If you'd like to copy and paste the result into Numbers or another spreadsheet, add the following:
set the_string to ""
repeat with this_number in the_numbers
set the_string to the_string & this_number & return
end repeat
set the_string to items 1 thru -2 of the_string as string
(134319)
The chance of having a duplicate in 1050 rows of RAND() function is pretty slim. Nonetheless, instead of using RAND() all by itself here is a way that will guarantee all are different:
=ROUND(RAND(),6)+ROW()/10^10
The 6 most significant digits will random. The last 4 digits are unique to the row. You can round the RAND() piece of it to more decimals to minimize the occurrence of duplicates in the most significant digits and divide the ROW() by a larger multiple of ten so the two don't overlap. As far as randomness goes, if there are any repeats in RAND(), the ones in the lower rows (higher row numbers) will be larger than those in upper rows. It probably makes no difference to what you are doing.
=ROUND(RAND(),9)+ROW()÷10^13 will have the 9 most significant digits random and the last 4 unique to the row.
Edit: I noticed I answered what you asked in your post but not what you asked in the title. RAND() provides a number between 0 and less than 1. So multiply by 49 and add 1 to get as close as you can get to 1-50. You have no chance of getting either 1 or 50 but the distribution in between should be okay.
MY APOLOGIES to the Numbers Community. I goofed; The title is correct ! - My POST is wrong...
My question was "How to Generate Random Number Between 1-50 without Repeat. The (My) post came out wrong. I pressed the Zero key instead of the dash. I am sorry, Bob Mayorga
I believe randbetween is what you are looking for. Try =Randbetween(1,50)
Hello
I presume what you want is a subset of shuffled distinct integers in range [1, 50], which can be obtained from column A of the following table when sorted by random numbers in column B.
Shuffled (excerpt) A1 shuffled A2 1 A3 2 A4 3 A5 4 B1 rand B2 =RAND() B3 =RAND() B4 =RAND() B5 =RAND()
* Table is built with Numbers v2.
Hope this may help,
H
Robert E. Mayorga wrote:
MY APOLOGIES to the Numbers Community. I goofed; The title is correct ! - My POST is wrong...
My question was "How to Generate Random Number Between 1-50 without Repeat. The (My) post came out wrong. I pressed the Zero key instead of the dash. I am sorry, Bob Mayorga
No problem. There was a suggestion to use RANDBETWEEN but you are likely to have duplicates with it. Hiroto's idea is to have a list of the numbers 1-50 and then mix them up. He did not show a function that does the re-ordering (he suggested sorting by the column of random numbers). RAND will work fine for manual sorting but if you want it to be automatic, the formulas I know of require all the random numbers to be unique. RAND() still has a very very very very very extremely unlikely chance of a repeat (did I say "very" enough times? probably not).
In the screenshot below, the formula in D is the one that does the reordering. It uses "ROW()-1" as the index. Row 2 will find the 1st largest random number from column B and return the number beside it in column C. Row 3 will find the 2nd largest random number, etc. Using ROW() makes the formula able to be filled down vs hardcoding it with a 1, then a 2, then a 3, etc. If you put the formula somewhere else in your table, you will have to adjust that part of it (and other changes may have to be made, like using ranges instead of full column references).
Hello
OK. Here's another table which yields automatically shuffled integers.
Shuffled (excerpt) A1 rand A2 =RAND() A3 =RAND() A4 =RAND() A5 =RAND() B1 rank B2 =RANK(A2,A) B3 =RANK(A3,A) B4 =RANK(A4,A) B5 =RANK(A5,A) C1 distinct? C2 =ISERROR(MODE(B)) C3 C4 C5
* C2 is to check if there's no repeated integers in column B, just in case.
Regards,
H
Thanks very much Niel. Your answer did the job.! Regards, Bob
Here's another way:
D1=COLUMN()−4
select D1, copy
select D1 to the end of row 1, paste
B2=IFERROR(OFFSET($D1, 0, C2), "")
C2=IF($A$1, RANDBETWEEN(0, MAX($1:$1)−(ROW()−2)), RANDBETWEEN(0, MAX($1:$1)−(ROW()−2)))
D2=IFERROR(IF((COLUMN()−4)≥$C2, E1, D1), "")
Select D2, copy
select cells D2 thru the end of row 2, paste
select cells B2 thru the end of row 2
hover the cursor over the bottom edge of the selection and drag the yellow dot down to the bottom of the table
the randomized values without duplicates will be in column C
Here is a dropbox link:
https://www.dropbox.com/s/pvtxcmt5a76wxty/RandomNoDups.numbers?dl=0
my method works by starting with the ordered list of numbers from 0 to n
then selecting a random number between 0 and n
remove that value in that position from the list
now pick a random number from 0 to (n-1)
remove that value in that position from the list
.
.
.
.until the list is empty
Made some refinements to make the random list appear in a separate table:
Add a new two column Table and call it "Random", then name the big table "Work"
copy the checkbox from the Work table cell A1 to the Random table cell A1
For the table Work:
C2=IF(Random::$A$1, RANDBETWEEN(0, MAX($1:$1)−(ROW()−2)), RANDBETWEEN(0, MAX($1:$1)−(ROW()−2)))
select cell C2, copy
select cells C2 thru the end of column C, paste
For the table Random
B1=Work::B2
select cell B1, copy
select column B, paste
you can also just hide all but the first two columns
Hello Wayne: I do not mean to be disrespectful, but I am not that smart with Numbers. I had difficulties in following your answer. I certainly appreciate all your efforts and thank you for trying to assist me. With appreciation, Bob
Bob,
No worries. I'm sure it looks ominous.
If you follow the directions carefully you should be able to make the table yourself. Knowing this may be a challenge, I provided a link so you can download the document. Did you try that?
Here is is again:
Here is a dropbox link:
https://www.dropbox.com/s/pvtxcmt5a76wxty/RandomNoDups.numbers?dl=0
Generate Random Number between 1-50 without repeats