[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-hackers] [PATCH] random returns the same number on x86_64 a
From: |
Jim Ursetto |
Subject: |
Re: [Chicken-hackers] [PATCH] random returns the same number on x86_64 all the time |
Date: |
Sun, 4 Mar 2012 10:14:34 -0600 |
On Mar 4, 2012, at 12:42 AM, John Cowan wrote:
>> That makes no sense when you are asking for an integer between 0 and 2^62-1.
>
> In that case the underlying interface should be asked to deliver two 32-bit
> values.
That gets you up to 53 bits due to the (double) scaling, but the bottom bits
will still be zero.
On Mar 3, 2012, at 11:02 PM, John Cowan wrote:
> This is why Common Lisp doesn't provide an interface giving you "a random
> integer", only a random integer in the range 0 to n for a given n.
Chicken does the same thing.
In fact if you just want to fill all 62 bits then you are better off with an
interface giving you "a random integer". Something like
#define C_random_exact() C_fix(((rand() & 0x7fffffff) << 31) | (rand() &
0x7fffffff))
assuming RAND_MAX = 0x7fffffff.
But the question is what are you going to do with those bits, and I don't know
how the hash table randomization works. I am simply letting Peter know that
the bottom bits are currently zero and should not be used, and if only 30 bits
are needed during the randomization, you might as well do (random 2^30-1)
instead of (random most-positive-fixnum) anyway.
Obviously the non-randomness of rand() is another limiting factor.
Jim