First off, I love autonumbers, and almost always use them. For this one project, however, I need my unique identifiers to have exactly six digits, so I wrote some very basic code to generate random numbers.

When converting the data over from the old version to the new one, I first call Randomize Timer. Then I assign new IDs as follows:

begin loop
lngID = Int(900000 * Rnd + 100000)
if lngID is unique, save new ID and exit loop
end loop

This range gives me a six digit number that will never start with 0. The problem is that my distribution is FUBAR. Running it now I get the following distribution based on the first digit of the ID:
Code:
Digit	IDs
1	368
2	335
3	292
4	257
5	226
6	177
7	152
8	91
9	34

Lowest ID: 100709
Highest ID: 994612
Running it a second time, I get:
Code:
Digit	IDs
1	340
2	333
3	317
4	265
5	225
6	182
7	145
8	94
9	31

Lowest ID: 100619
Highest ID: 982853
Clearly the range is working properly, and it successfully gives me the thousands of unique IDs I need, but the distribution is pissing me off. Not only does it offend my perfectionist nature, but it's messing with the intent of these numbers in the first place.

This system will eventually be managing tens of thousands of files on disk. Too many to store in a single data folder with any kind of decent access speed, so I spread them out over 10 subfolders, each (theoretically) holding 10% of the files.

I can get around the problem by using the last digit instead of the first to define which subfolder a given file belongs in; the last digit spread is uniform. But what is up with this biased distribution on the first digit? I certainly didn't code anything in there to skew the results like this.

Any ideas?

Could it be that the Rnd function is not liking the large numbers?
Could it be that I'm doing two tables at once? (Both showing the same bias.)
Could it be something inherant to the random number generator that only becomes apparent when filtering out the duplicates?

If nobody has any ideas, I'm open to any manual algorithms for generating random numbers.