in reply to Re: Randomizing Large Integers
in thread Randomizing Large Integers

Is 32K a limitation of the standard rand function?

The macro (uconfig.h, line 3368 in 5.8.8 or 4057 in 5.10.0) looks like only 15 bits are being used:

#define Drand01() ((rand() & 0x7FFF) / (double) ((unsigned long)1 << +15)) ^^^^

Update: though, a somewhat closer look suggests this might be configuration dependent (at least, Configure checks for drand48()), so maybe I spoke too soon...

Update2: just ran a test build on a system which has drand48()... et voila, the macro ends up being defined as

#define Drand01() drand48()

So, as often, the answer is: it depends :)

Replies are listed 'Best First'.
Re^3: Randomizing Large Integers
by mscharrer (Hermit) on May 19, 2008 at 20:29 UTC
    15 bit of the input or of the output?

    I get the following behavior that lets me assume that 32 bit random integers work:

    # perl -e 'printf "%010x\n", int rand 2**16' 00000052e2 # perl -e 'printf "%010x\n", int rand 2**32' 006f7ae0c5 # perl -e 'printf "%010x\n", int rand 2**64' 00ffffffff

    i.e. rand 2**N seems to return a N bit random integer, up to N = 32 but not above.

      15 bit of the input or of the output?

      15 bits of entropy. For a given argument, rand will only spit out 215 different results (spread over the requested range).