fear and loathing in SGI's random-number generator

Levente Farkas lfarkas@mindmaker.hu
Fri Aug 11 00:55:00 GMT 2000


Phil Edwards wrote:
> 
> Levente Farkas <lfarkas@mindmaker.hu>:
> > Phil Edwards wrote:
> > > Anybody have any thoughts as to alleviate this?  Maybe provide some
> > > seed_random() wrapper around the seeders that performs the same conditional
> > > compilation?  Surely somebody has used random_shuffle before and solved
> > > this already?  What do they use at SGI?
> >
> > IMHO those who realy need "random" random use thier own random generator
> 
> Of course.  But it needs to not be surprising for people who just want
> simple pseudorandom behavior.
> 
> > or know about
> > srand48 (look into the code) those who just need "some" random generator
> > the deafult may be good.
> 
> But the default (srand) has no effect when the newer RNG is used.  We can't
> expect casual users to dig down into the headers far enough to figure out
> what's going on.  It took me almost five minutes, and I know the headers
> pretty well -- somebody who doesn't know the guts of libstdc++-vN wouldn't
> even know where to begin to look in the code.  And shouldn't have to.
> 
> Perhaps I'm making too much of this.
> 
> > anyway I think it'd be good to put srand48 into namespace std as srand
> > on platform which support it and those who realy use c++ eg. <cstdlib>
> > find that srand and don't have to care about it.
> 
> We don't supply srand nor srand48... and I don't think we should silently
> rename one to be the other.  If the system C library desginers want to make
> their default RNG be the 48-bit one, that's excellent, but out of our hands.

what I wanna said that those who really use c++ ie. use evrything from
namespace std:: won't recognize if we put srand48 into namespace std as srand
random_shuffle (and friends) use __random_number which choose the right random
generator:
---------------
inline _Distance __random_number(_Distance __n) {
#ifdef __STL_NO_DRAND48
  return rand() % __n;
#else
  return lrand48() % __n;
#endif
}
---------------
so that would be a simple solution. the only problem those who wanna use
the ::rand they need use ::srand and thats all.

 -- Levente
 "The only thing worse than not knowing the truth is
  ruining the bliss of ignorance."


More information about the Libstdc++ mailing list