multible random numbers 
Author Message
 multible random numbers

Usually, when I want a random number I use this:

srand(time|$$);
$number = rand(100);

I now have need of 3 random numbers in a row, yet when I try

srand(time|$$);
number1 = rand(100);
number2 = rand(100);
number3 = rand(100);

I received the same value for number1, number2, and number3.

Anyone have a suggestion for getting 3 equally random numbers?

Thanks!

ah.

--
Andrew Hunt
Wolf Song Design



Thu, 17 Jul 1997 07:13:15 GMT  
 multible random numbers


Quote:
>Usually, when I want a random number I use this:

>srand(time|$$);

That favors seeds with 1's in the low order bits.  Use srand(time^$$) to get a
better distribution of seeds.

Quote:
>$number = rand(100);

>I now have need of 3 random numbers in a row, yet when I try

>srand(time|$$);
>number1 = rand(100);
>number2 = rand(100);
>number3 = rand(100);

>I received the same value for number1, number2, and number3.

Since that contradicts what is expected, what is documented, and what happens
for everyone else, perhaps you have a buggy version, or perhaps even the code
in which you *used* those values is buggy (after you program a while, you will
come to realize that it is almost always something *you* did that is wrong).
So why not post the actual code that fails and the version and platform of
your perl?
--
<J Q B>


Thu, 17 Jul 1997 07:35:31 GMT  
 multible random numbers

Quote:
>Usually, when I want a random number I use this:
>I now have need of 3 random numbers in a row, yet when I try
>srand(time|$$);
>number1 = rand(100);
>number2 = rand(100);
>number3 = rand(100);
>I received the same value for number1, number2, and number3.

Andrew
Why not reseed before each assignment:=> 3 srand statements?
bru
--
Bruce Wallace           Wallace Systems Inc.    (212) 334-1065


Sat, 19 Jul 1997 02:31:04 GMT  
 multible random numbers

: Usually, when I want a random number I use this:
:
: srand(time|$$);
: $number = rand(100);
:
: I now have need of 3 random numbers in a row, yet when I try
:
: srand(time|$$);
: number1 = rand(100);
: number2 = rand(100);
: number3 = rand(100);

I presume you used dollar signs on the variables in the actual code.

: I received the same value for number1, number2, and number3.

Is it an interesting number?

: Anyone have a suggestion for getting 3 equally random numbers?

Either your rand() is broken, or you've done something silly.  We can't
tell which without more context.  (Unless you DID omit the dollar signs.)

Larry



Sun, 20 Jul 1997 02:40:22 GMT  
 multible random numbers
Thanks to all that have responded, both public and private.

Almost all of the suggestions worked, esp the one that mentioned rechecking
the code to make sure that I was *really* asking for 3 unique random numbers.

It turns out, I wasn't.  <:^{

Many Thanks to all!

ah.

--
Andrew Hunt
Wolf Song Design



Sun, 20 Jul 1997 14:11:01 GMT  
 multible random numbers

: >Usually, when I want a random number I use this:
: >I now have need of 3 random numbers in a row, yet when I try
: >srand(time|$$);
: >number1 = rand(100);
: >number2 = rand(100);
: >number3 = rand(100);
: >I received the same value for number1, number2, and number3.
: Andrew
: Why not reseed before each assignment:=> 3 srand statements?

Because then you are very likely to get the same three numbers, since
you're probably using the same seed.  You're not supposed to have
to reseed rand() each time.  Otherwise you'd need a random number
generator to produce the seeds.  Your infinite regress detectors
should be kicking in about now.

Larry



Mon, 21 Jul 1997 02:18:11 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Random number isn't random.

2. Searching Multible Search Engines Script

3. Searching Multible Search Engines Script

4. random numbers

5. Perl Q: Re: Random Numbers

6. Random Number question

7. How to generate random number in perl - NEWBIE

8. Random Number???

9. Random Number Problem

10. Pseudo random number generating

11. Random Numbers in Win32

12. random number generation

 

 
Powered by phpBB® Forum Software