Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Six digit random number generator?

Is there a formula or function I can use to generate 500 or so six digit random numbers? I need to assign unique six digit numbers for keypad access to a restricted area.


Thanks,

Bjohnston

Posted on Sep 28, 2019 4:30 PM

Reply
Question marked as Best reply

Posted on Sep 28, 2019 5:23 PM

Hi Bjohnston,



Formula in B2 =RANDBETWEEN(0,9)

Fill right to G2 then fill down.


Formula in H2 (and fill down) =B2&C2&D2&E2&F2&G2


Formula in I2 (and fill down) =COUNTIF(H$1:H2,H2)

That will check for duplicates. Any value greater than 1 is not unique.


Now select Column H, copy then Menu > Edit > Paste Formula Results

That will freeze the values.


Regards,

Ian.


16 replies
Question marked as Best reply

Sep 28, 2019 5:23 PM in response to bjohnston

Hi Bjohnston,



Formula in B2 =RANDBETWEEN(0,9)

Fill right to G2 then fill down.


Formula in H2 (and fill down) =B2&C2&D2&E2&F2&G2


Formula in I2 (and fill down) =COUNTIF(H$1:H2,H2)

That will check for duplicates. Any value greater than 1 is not unique.


Now select Column H, copy then Menu > Edit > Paste Formula Results

That will freeze the values.


Regards,

Ian.


Sep 29, 2019 6:08 PM in response to Wayne Contello

Here's a way you can use:

make the first row a header row.

A2=NUMTOBASE(ROW()+1000×RANDBETWEEN(0,999), 10, 6)

B2=COUNTIF(A, A2)


select cells A2 and B2, copy

select cells S2 thru the end of column B, paste


B1="Duplicates = "&COUNTIF(B, ">1")


I think using this method unique IDs are guaranteed, and I added the formulas in column B to confirm this.

Sep 30, 2019 2:04 PM in response to bjohnston

Hi Bjohnston,


Locking will not stop the RANDBETWEEN function from recalculating with every little change to the document.

You can "freeze" the results by replacing formulas with the last calculated values.

Select the whole table (click on the "Bullseye" top left).



Menu > Edit > Copy

Menu > Edit > Paste Formula Results.


Regards,

Ian.


P.S. before you do that, you may want to Save as Template to preserve the formulas for future use.

Ian.


Sep 29, 2019 7:09 AM in response to Yellowbox

Hi Ian,


I wondered why you were not just using

=RANDBETWEEN(0,999999)

until I tried it and got 2169 as a result. Not the same as 002169 for these purposes!

I hadn't thought of checking for duplicates.


Here is a solution that does it with one formula.

=ROUND(RAND(),6)×1000000

Edit: Whoops! I will still return a 5 digit #.


quinn


Six digit random number generator?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.