default random object?

Jarrett Billingsley jarrett.billingsley at gmail.com
Mon Feb 16 08:14:13 PST 2009


On Fri, Feb 13, 2009 at 8:10 PM, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:

I feel like I'm mimicking everyone else by now, but:

> 1. Are you cool with making the rng the last parameter and give it a default
> value?

Yes.

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

Yes.

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

Hell no.

> 4. While we're at it, should uniform(a, b) generate by default something in
> [a, b] or [a, b)? Someone once explained to me that generating [a, b] for
> floating point numbers is the source of all evils and that Hitler, Stalin
> and Kim Il Sung (should he still be alive) must be using that kind of
> generator. Conversely, generating [a, b) is guaranteed to bring in the long
> term everlasting peace to Earth. My problem however is that in the integer
> realm I always want to generate [a, b]. Furthermore, I wouldn't be happy if
> the shape of the interval was different for integers and floating point
> numbers. How to break this conundrum? Don't forget that we're only worrying
> about defaults, explicit generation is always possible with self-explanatory
> code:

Almost all of my uses of random numbers involve indexing arrays, so
[a, b) would be most useful for me.  But again, I could certainly
"alias uniform!("[)") uniformIdx;".



More information about the Digitalmars-d mailing list