default random object?
dsimcha
dsimcha at yahoo.com
Sat Feb 14 07:37:16 PST 2009
== Quote from Walter Bright (newshound1 at digitalmars.com)'s article
> Andrei Alexandrescu wrote:
> > 2. The global random generator will be allocated per thread. Are you
> > cool with this too?
> That could have speed problems with a tight loop accessing thread local
> storage.
I don't think this matters, since for apps that really need it, a RNG can be
explicitly passed in. This is purely a convenience feature for when you want
random number generation to "just work" even if it's not the most efficient thing
in the world. Also, checking thread_needLock() is dirt cheap, in my experience
faster than accessing TLS. You could also have a global, non-thread local RNG
that is used if a check to thread_needLock() returns false.
> If it's a shared global with no locking, the thread randomness
> will increase its randomness <g>.
Yay, D's getting hardware random number generators!!!
More information about the Digitalmars-d
mailing list