Assigning random #'s

B

bgarey

I have a table where i will need to make "n" number of records each with a
random #. I know that I can use autonumber to creat the random #'s. My
question is how can use a form to set "n" to tell the computer how many
records I will need?
For instance, in one case i may need 400 random #'s. In another I may wnt
1600 random #'s.
 
A

Alex White MCDBA MCSE

That's a loaded question,

Because do you mean really random (2 records in the same series could have
the same number, the number 10 could happen twice),

this will generate a number between 1 and 2000


Public Function GetNextNum As Long
Randomize
GetNextNum = Int((2000 - 1 + 1) * Rnd + 1)
End Function

or

random within 2 parameters e.g. between 1 and 2000 but not repeated.

well you will have to generate the number and check if its been used before
an if so generate a new number
 
B

bgarey

THanks for the info, but the random #'s must be different, but could I use
something like you gave me but make it sequenced. That way I could make the
correct number of records, and let auto number assign the random numbers in a
differnt field?
 
A

Alex White MCDBA MCSE

You need to be a bit more specific, because the words sequenced and random
mean totally different things, explain what you are trying to achieve and I
am sure there is a solution.
 
B

bgarey

I am setting up a data base where I will assign "n" number of users a
password that they will use before entering data. This is at the school where
I teach. I need random unigue numbers for each set of users. The number of
users will change from time to time, and I will create new passwords. I can
do this myself within the tables, but I would like to set it up so that
another teacher can do this without my help. I don't want other teachers to
have access to the tables, etc. Not that I don't trust their integrity, but I
don't want them to mess up my formats, macros, etc.
 
M

Mike Painter

bgarey said:
THanks for the info, but the random #'s must be different, but could
I use something like you gave me but make it sequenced. That way I
could make the correct number of records, and let auto number assign
the random numbers in a differnt field?

If they must be different then they are technically not random.
However if you use the random feature of the autonumber
the probability of two of them being the same is very small.

You could use INSERT INTO in a loop to generate the records.
 
Top