[openbeos] Re: is rand() really random?

  • From: Scott Mansfield <thephantom@xxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Fri, 09 Apr 2004 14:33:20 -0700

 
On Friday, April 09, 2004, at 02:18PM, Andre Stark <An.Stark@xxxxxx> wrote:

>Hello there,
>this is not really an OBOS problem, but a BeOS one. Everytime i execute 
>the following code:
>
>for (int i = 0; i < 100; i++)
>               cout << "Random:" << rand() <<endl;
>
>the resulting values are exactly the same? Until now i do'nt know much 
>about C++ programming, but normally random numbers are generated by 
>including system time in some kind. How does this work on BeOS?

Yes, the behavior you're observing is correct.  You'll need to seed the random 
number generator with srand() -- I usually use seconds since the epoch as a 
seed.

Cheers,
Scott

Other related posts: