Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Rnd


Message #1 by "O'Hara, Elliott M" <EMOHARA@k...> on Thu, 22 Mar 2001 12:26:31 -0500
So I want to generate four UNIQUE rnd numbers and put them in an array.

can I seed Rnd to assure that they are indeed unique or do I have to check

the array to see if the next value already exists?

thanks guys

Message #2 by "Wally Burfine" <oopconsultant@h...> on Thu, 22 Mar 2001 21:31:22 -0000
Elliott,



The random number generator doesn't generate unique numbers, only random 

(psudo) numbers. You will have to put them into an array and check the 

array. Or put them into a variable string and do an instr on the number.



Regards,

Wally







>From: "O'Hara, Elliott M" <EMOHARA@k...>

>Reply-To: "ASP Web HowTo" <asp_web_howto@p...>

>To: "ASP Web HowTo" <asp_web_howto@p...>

>Subject: [asp_web_howto] Rnd

>Date: Thu, 22 Mar 2001 12:26:31 -0500

>

>So I want to generate four UNIQUE rnd numbers and put them in an array.

>can I seed Rnd to assure that they are indeed unique or do I have to check

>the array to see if the next value already exists?

>thanks guys

>
Message #3 by "Anil Rhemtulla" <AnilR@T...> on Fri, 23 Mar 2001 09:55:30 +0100
You need to check to ensure new random numbers are in fact unique. However,

as Rnd should produce a 32 bit number, there are over 4 trillion (2 ^ 32)

possible numbers generated. Selecting 4 of these, the chance you get two or

more the same is about 1 in 700 million (you've got about 50x greater chance

of winning the lotto!!).



So in short, yes you should check if it's mission critical - but a fail time

of once out over every 700 million is not too threatening!!



I'm not sure why you need unique random numbers (do they need to be

random?), but perhaps a method such as



for i = 1 to 4

    myNum = Round(Rnd() * 1000000)    ' Create a random number between 1 and

1 000 000

    myNum = myNum * 10 + i                 ' append the index of the number

to ensure the number is unique (assume index < 10)

next





Cheers,

Anil



Sevina Technologies

www.Sevina.com





----- Original Message -----

From: "O'Hara, Elliott M" <EMOHARA@k...>

To: "ASP Web HowTo" <asp_web_howto@p...>

Sent: Thursday, March 22, 2001 6:26 PM

Subject: [asp_web_howto] Rnd





> So I want to generate four UNIQUE rnd numbers and put them in an array.

> can I seed Rnd to assure that they are indeed unique or do I have to check

> the array to see if the next value already exists?

> thanks guys



Message #4 by "O'Hara, Elliott M" <EMOHARA@k...> on Fri, 23 Mar 2001 06:50:00 -0500
sorry, left out some very important issues...

I need to generate 4 UNIQUE integers between 1 and 20... the chances of

duplicates is in fact pretty good...

I've sience solved the problem though.. appreciate the response.



-----Original Message-----

From: Anil Rhemtulla [mailto:AnilR@T...]

Sent: Friday, March 23, 2001 3:56 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Re: Rnd





You need to check to ensure new random numbers are in fact unique. However,

as Rnd should produce a 32 bit number, there are over 4 trillion (2 ^ 32)

possible numbers generated. Selecting 4 of these, the chance you get two or

more the same is about 1 in 700 million (you've got about 50x greater chance

of winning the lotto!!).



So in short, yes you should check if it's mission critical - but a fail time

of once out over every 700 million is not too threatening!!



I'm not sure why you need unique random numbers (do they need to be

random?), but perhaps a method such as



for i = 1 to 4

    myNum = Round(Rnd() * 1000000)    ' Create a random number between 1 and

1 000 000

    myNum = myNum * 10 + i                 ' append the index of the number

to ensure the number is unique (assume index < 10)

next





Cheers,

Anil



Sevina Technologies

www.Sevina.com





----- Original Message -----

From: "O'Hara, Elliott M" <EMOHARA@k...>

To: "ASP Web HowTo" <asp_web_howto@p...>

Sent: Thursday, March 22, 2001 6:26 PM

Subject: [asp_web_howto] Rnd





> So I want to generate four UNIQUE rnd numbers and put them in an array.

> can I seed Rnd to assure that they are indeed unique or do I have to check

> the array to see if the next value already exists?

> thanks guys



Message #5 by "Wally Burfine" <oopconsultant@h...> on Fri, 23 Mar 2001 14:57:12 -0000
Since the set is very small, why not use 5,10,15 and 19. that way you don't 

have to calculate anything



Regards,

Wally



>From: "O'Hara, Elliott M" <EMOHARA@k...>

>Reply-To: "ASP Web HowTo" <asp_web_howto@p...>

>To: "ASP Web HowTo" <asp_web_howto@p...>

>Subject: [asp_web_howto] Re: Rnd

>Date: Fri, 23 Mar 2001 06:50:00 -0500

>

>sorry, left out some very important issues...

>I need to generate 4 UNIQUE integers between 1 and 20... the chances of

>duplicates is in fact pretty good...

>I've sience solved the problem though.. appreciate the response.

>

>-----Original Message-----

>From: Anil Rhemtulla [mailto:AnilR@T...]

>Sent: Friday, March 23, 2001 3:56 AM

>To: ASP Web HowTo

>Subject: [asp_web_howto] Re: Rnd

>

>

>You need to check to ensure new random numbers are in fact unique. However,

>as Rnd should produce a 32 bit number, there are over 4 trillion (2 ^ 32)

>possible numbers generated. Selecting 4 of these, the chance you get two or

>more the same is about 1 in 700 million (you've got about 50x greater 

>chance

>of winning the lotto!!).

>

>So in short, yes you should check if it's mission critical - but a fail 

>time

>of once out over every 700 million is not too threatening!!

>

>I'm not sure why you need unique random numbers (do they need to be

>random?), but perhaps a method such as

>

>for i = 1 to 4

>     myNum = Round(Rnd() * 1000000)    ' Create a random number between 1 

>and

>1 000 000

>     myNum = myNum * 10 + i                 ' append the index of the 

>number

>to ensure the number is unique (assume index < 10)

>next

>

>

>Cheers,

>Anil

>

>Sevina Technologies

>www.Sevina.com

>

>

>----- Original Message -----

>From: "O'Hara, Elliott M" <EMOHARA@k...>

>To: "ASP Web HowTo" <asp_web_howto@p...>

>Sent: Thursday, March 22, 2001 6:26 PM

>Subject: [asp_web_howto] Rnd

>

>

> > So I want to generate four UNIQUE rnd numbers and put them in an array.

> > can I seed Rnd to assure that they are indeed unique or do I have to 

>check

> > the array to see if the next value already exists?

> > thanks guys

>

>
Message #6 by "O'Hara, Elliott M" <EMOHARA@k...> on Fri, 23 Mar 2001 10:31:18 -0500
its for a Process Surviellance team on the Space Shuttle main engine...

I'm making a page that tells them to go observe 4 random tasks...

It has to be random if I use 5,10,15,and 19

the techs at 1,2,3,4 ect... could be planting bombs in the orbitor and i'd

get shot because I never told the Proc Surv. guy to go check them..

:o)

got to be random...

I've got it working now, just couldn't do it in a for next loop..

i did a 



this = myrandom

do 

that = rnd(blahblahblah)

loop until this<>that

-----Original Message-----

From: Wally Burfine [mailto:oopconsultant@h...]

Sent: Friday, March 23, 2001 9:57 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Re: Rnd





Since the set is very small, why not use 5,10,15 and 19. that way you don't 

have to calculate anything



Regards,

Wally



>From: "O'Hara, Elliott M" <EMOHARA@k...>

>Reply-To: "ASP Web HowTo" <asp_web_howto@p...>

>To: "ASP Web HowTo" <asp_web_howto@p...>

>Subject: [asp_web_howto] Re: Rnd

>Date: Fri, 23 Mar 2001 06:50:00 -0500

>

>sorry, left out some very important issues...

>I need to generate 4 UNIQUE integers between 1 and 20... the chances of

>duplicates is in fact pretty good...

>I've sience solved the problem though.. appreciate the response.

>

>-----Original Message-----

>From: Anil Rhemtulla [mailto:AnilR@T...]

>Sent: Friday, March 23, 2001 3:56 AM

>To: ASP Web HowTo

>Subject: [asp_web_howto] Re: Rnd

>

>

>You need to check to ensure new random numbers are in fact unique. However,

>as Rnd should produce a 32 bit number, there are over 4 trillion (2 ^ 32)

>possible numbers generated. Selecting 4 of these, the chance you get two or

>more the same is about 1 in 700 million (you've got about 50x greater 

>chance

>of winning the lotto!!).

>

>So in short, yes you should check if it's mission critical - but a fail 

>time

>of once out over every 700 million is not too threatening!!

>

>I'm not sure why you need unique random numbers (do they need to be

>random?), but perhaps a method such as

>

>for i = 1 to 4

>     myNum = Round(Rnd() * 1000000)    ' Create a random number between 1 

>and

>1 000 000

>     myNum = myNum * 10 + i                 ' append the index of the 

>number

>to ensure the number is unique (assume index < 10)

>next

>

>

>Cheers,

>Anil

>

>Sevina Technologies

>www.Sevina.com

>

>

>----- Original Message -----

>From: "O'Hara, Elliott M" <EMOHARA@k...>

>To: "ASP Web HowTo" <asp_web_howto@p...>

>Sent: Thursday, March 22, 2001 6:26 PM

>Subject: [asp_web_howto] Rnd

>

>

> > So I want to generate four UNIQUE rnd numbers and put them in an array.

> > can I seed Rnd to assure that they are indeed unique or do I have to 

>check

> > the array to see if the next value already exists?

> > thanks guys

>

>


  Return to Index