Unique Random Number

CSCS

Registered User.
Local time
Today, 11:19
Joined
Jan 10, 2004
Messages
91
Hi everyone,

I want to generate a unique random number of 5 digits, giving that the first digit is retrived from another field.

Any help will be very much appreciated!

Best Regards,
CS
 
This will give you a 5 digit random number

Dim iMax as Long
Dim iMin as Long
Dim MyNum as Long
Randomize(Timer)
iMax=99999
iMin = 10000
MyNum = Int((iMax - iMin + 1) * Rnd + iMin)

I'm not sure if your 1st digit is part of the 5 numbers or in addition to it.

If its in addition, then you can just use cstr to convert to a string and add it to the beginning or increase your imax and imin by one 9 and 0 and use the exmaple below.

If your field digit is part of the 5 digits then try

'Assumes MyDigit is your field value
Dim iMax as Long
Dim iMin as Long
Dim MyNum as Long
Randomize(Timer)
iMax=Clng(MyDigit & "99999")
iMin = Clng(MyDigit & "00000")
MyNum = Int((iMax - iMin + 1) * Rnd + iMin)
 

Users who are viewing this thread

Back
Top Bottom