default random object?

Steve Schveighoffer schveiguy at yahoo.com
Fri Feb 13 20:38:41 PST 2009


On Fri, 13 Feb 2009 17:10:29 -0800, Andrei Alexandrescu wrote:


> 2. The global random generator will be allocated per thread. Are you
> cool with this too?

Good idea.  Random number generators should not require locking in the 
most common case.

> 
> 3. How should the global rng be initialized? To always generate the same
> sequence, or not?

Not.  And even between threads not.  So some combination of time and 
thread id for seed is probably in order.  If I want to "just use" random 
numbers in a simple program, I don't want to see the same values every 
time.  If I want to repeat the values every time, I'll take the time to 
seed it so that happens.

> 4. While we're at it, should uniform(a, b) generate by default something
> in [a, b] or [a, b)?

[a,b)

Every other piece of range-like code is zero based, and excludes the 
upper bound.  This should be no different.  It makes the code simpler too.

-Steve



More information about the Digitalmars-d mailing list