[thelist] HELP ASP gurus -- random numbers is hard

Anthony Baratta Anthony at Baratta.com
Tue Dec 5 13:06:14 CST 2000


At 12:40 PM 12/5/2000 -0500, you wrote:

>But seriously. All I want to do is put 10 unique random numbers into an
>array. I can get the array and I can get 10 numbers, but they're not all
>unique enough. I've tried some incredibly complicated nested loops, but
>I'm just generating errors with that. Please give a little if you can.

If you only need uniqueness between the 10 numbers:

Instead of an array use a dictionary object....

'' I use the Cap Rock Dictionary Object
Set dictRandomList = Server.CreateObject("caprock.dictionary")
varRandomListLength = 10

'' This will iterate until you get 10 unique numbers
while (dictRandomList.Count < varRandomListLength)
         dictRandomList(Int(1000*Rnd)) = Int(1000*Rnd)
wend

If you want uniqueness "forever":

If you have a database, compare each new random number against the database 
and stuff it into the database if its determined to be unique.


---
Anthony Baratta
President
Keyboard Jockeys





More information about the thelist mailing list