On Mar 16, 2010, at 5:47 PM, Kirk, Benjamin (JSC-EG311) wrote: > not sure, but on my OSX box the first line of 'man srand' says 'bad random > number generator'
Just a general warning to everyone out there.... the OSX implementation of rand() gives EXTREMELY non-random numbers as the first number after a seed(). This is really easy to see if you just write a little program with an increasing seed and print out the first number out of rand each time.... the number is predictable and actually just increases along with the seed. I ran into this last year when we were simulating (in probably not a great way... but note that we were doing it to achieve a specific purpose... not just because we were dumb!) some random processes. It got to the point that I even had a few conversations with some of the Darwin developers at Apple about it. Ultimately though... they just told me "that's the way it is". Even though I couldn't get similar behavior out of any other OS. Of course any PRNG has it's drawbacks... but I consider this drawback particularly bad. Yes, you shouldn't be using rand() for anything sensitive anyway (like for security purposes)... but it still feels like a bad idea to have the first number be so predictable. One workaround for it is just to throw the first number away after a seed(). Basically just do seed(); rand(); . This will give you a sufficiently random _next_ number. Derek ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Libmesh-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libmesh-users
