Re: random is not random enough?
velthuijsen_at_hotmail.com
Date: 12/29/04
- Next message: KPB: "Re: random is not random enough?"
- Previous message: Michael Mair: "Re: two-dimensional array"
- In reply to: JNY: "random is not random enough?"
- Next in thread: velthuijsen_at_hotmail.com: "Re: random is not random enough?"
- Reply: velthuijsen_at_hotmail.com: "Re: random is not random enough?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Dec 2004 07:26:24 -0800
JNY wrote:
> I am using random to generate random numbers, thus:
>
> int x,y;
>
> for (y = 0;y < 5;y++)
> {
> x = random(50);
> cout << x;
> }
>
> When I run this program, 5 random numbers are produced. However, if
I
> stop the program and re-run it, the same sequence is produced. Am I
> forgetting to do something? Is there another random number generator
> which I could try?
Random is not a basic C++ function. The ones you'd want to use are
srand and rand. because of this I'm going to assume a few things.
That is that under the hood this random calls srand once and then calls
rand after that.
If that is the case then your random does exactly what it is supposed
to do.
The rand function is a pseudo random generator. It starts from a seed
number (50 in this case) and based on that value returns you the next
value in a sequence (and uses the returned value to calculate the next
value of the sequence).
- Next message: KPB: "Re: random is not random enough?"
- Previous message: Michael Mair: "Re: two-dimensional array"
- In reply to: JNY: "random is not random enough?"
- Next in thread: velthuijsen_at_hotmail.com: "Re: random is not random enough?"
- Reply: velthuijsen_at_hotmail.com: "Re: random is not random enough?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|