Generating Random Numbers - Tough One

L

Legacy 5232

Guest
Hi Everyone

I need to generate about 2695 random numbers in column A that are 7 digits long, between 1000000:9999999, do not start with zero, and are not duplicates of each other. Does anyone know the formula?

Thanks
Jacob
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Oh lawdy! I saw these pages, and they look greek to me, anyone have a better suggestion? Thanks for all your help! Jacob
 
Upvote 0
check MRand which is part of the Add-in Morefunc.

See add-in information at top of messages.
 
Upvote 0
Very easy one. Put the following formula in a cell, then copy and paste into the other cells: = RANDBETWEEN(1000000,9999999)
 
Upvote 0
Fiddler:

How do you accomodate the possible duplicate numbers?

plettieri
 
Upvote 0
No duplication is a more difficult problem. The easy answer previously given would apply if we are to randomly sample a finite population WITH REPLACEMENT after each random selection.

For sampling without replacement, one method comes to mind, but it would involve writing some Visual Basic code to check each successive random number for duplication. If duplicated, simply call RANDBETWEEN again until you find a nonduplicate number. However, as the range of numbers between 1000000 and 9999999 get used up, we will run into a system resource issue - we may be calling RANDBETWEEN for a long long time before getting a nonduplicate.

I suspect the best way would be to first assign index numbers 0 through 8999999 to the range (i.e. 0 is assigned to 1000000, 1 is assigned to 1000001, etc.), then perform RANDBETWEEN(0,8999999) on the indices. Once the first index is randomly chosen, "shrink" the list up by reassigning every index after the chosen index to be index - 1. Now you deal with randomly choosing from a successively smaller list so the resource issue is no longer an problem. However, this method also requires some Visual Basic backend code, with "for" loops. Also, not being an Excel expert, I am assuming you can list 9000000 numbers on a column in an Excel worksheet. Plus, the "shrinking" algorithm needs some work even though the concept is not difficult. I wish I had some time to do it.... - sorry, no easy solution....
 
Upvote 0
Given the info available in the links above, it is not clear why you suggest this approach :)
 
Upvote 0
Fiddler said:
Plus, the "shrinking" algorithm needs some work even though the concept is not difficult. I wish I had some time to do it.... - sorry, no easy solution....
Except that the code -- in fact, much faster algorithms -- are already available *and* the OP has been pointed to them!
 
Upvote 0

Forum statistics

Threads
1,221,622
Messages
6,160,887
Members
451,676
Latest member
Assy Bissy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top