Summary: Use: random(). Avoid rand(), lrand48(). Random number generating is tricky at best, and it is easy to get bitten. There are at least 3 different C pseudo random number generating functions: rand(), lrand48(), random(). When trying to generate random 0's and 1's with code similar to RANDOM % 2 despite seeding the generator with various values, only 4 different sequences were obtained. Actually it is cheaper to use RANDOM & 01 (A) Apparently both RANDOM = lrand48(), and RANDOM = rand() have low order bits which cycle! It seems the correct way to generate random bits with these functions is (int)(2.*RANDOM / (RAND_MAX+1.)) (B) which avoids the low order bits. Better to use RANDOM = random() which does not have the cycling problem. Note also that on some systems, initstate() is recommended over srandom().