It is well know that the rand() function returns numbers whose lowest bits are far from random. Try the new 48-bit random generators from UNIX System V instead.