Building a random number genorator is really that hard when you think about it. However, if you are going to use it for creating a key or something to that effect. You will also need to insure that the key that you are using has not already been used in the database. 1) First you need to DIM your variables and run the Randomize feature. If you don't run Randomize you will cause a static "seed" point for the randomizer and it will always return the same event. Forever.
Dim RandsomNumber Randomize
2) If the database is completely empty then create a number and finish.
If rs.EOF Then 'If the database is empty do this RandomNumber = (Int((1000000-1+1)*Rnd+1))
3) Otherwise you want to check the database to insure the number isn't there.
Else If RandomNumber = "" Then RandomNumber = (Int((1000000-1+1)*Rnd+1)) If RandomNumber = rs.fields.item("CLIENTID") Then Do While RandomNumber = rs.fields.item("CLIENTID") Randomize RandomNumber = (Int((1000000-1+1)*Rnd+1)) Loop End If End If End If
By folling this procedure you will create a random number upto 1,000,000. You can increase or lower this if you want to. You can also chacters other then numbers. Randomizing actual characters it used for creating things such as software keys or large variable items. Usually this is done in a fashion of having a base 28 array built. A through Z and 1 through 9 minus all vowels. You want to remove the vowels from the Randomizer because of any interesting 3 and 4 letter words that can be created.
All you need to do to randomize characters is build your array;
Dim arrMyarray arrMyarray(0) = "A" arrMyarray(1) = "B" arrMyarray(2) = "C"
Randomize
This will cause the Randomizer to randomize the items actually contained in the systems memory for your session. Since those items are character it will work with those.
|