[#1026] Is this a bug? — Dave Thomas <Dave@...>

18 messages 2000/01/03

[#1084] Infinite loop — Dave Thomas <Dave@...>

17 messages 2000/01/11

[#1104] The value of while... — Dave Thomas <Dave@...>

24 messages 2000/01/11

[ruby-talk:01064] Re: rand() / drand48()

From: Andrew Hunt <andy@...>
Date: 2000-01-07 18:48:27 UTC
List: ruby-talk #1064
    >  * drand48() requires srand48() before calling it.  So we have to
    >    supply some constant (?) seed to srand48() for uninitialized
    >    rand() invocation, if we want this behavior.  Do you think
    >    arbitrary integer (say 42) would be sufficient?
    >
    >  * Perl seems to give up this behavior.  Does Ruby really need this
    >    behavoir?

Perl's srand defaults to time(0L), but you can also call
srand with a constant.

I've written a number of programs where I've needed to seed the
random number generator with a constant in order to get
a predictable, random stream (as for regression testing).  Other
times of course, I'd want it to be random.  Process id and
time shifted around a bit makes a nice default, I think, but
we still need the ability to seed the generator ourselves.

/\ndy

In This Thread

Prev Next