chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] u8vector to numbers bignum


From: Stephen Eilert
Subject: Re: [Chicken-users] u8vector to numbers bignum
Date: Fri, 29 May 2015 11:48:47 -0300

On Thu, May 28, 2015 at 9:09 PM, John Cowan <address@hidden> wrote:
Peter Bex scripsit:

> If this is such an important feature it may make more sense to include
> a "proper" PRNG.

Different applications will want fast crude random-ish numbers, PRNGs,
cryptographic PRNGs, or full quantum randomness, with tradeoffs for
speed and quality.  Since that's so, I'd rather require programmers
to make the choice up front rather than fall back on some dubious
OS version that does who-knows-what.


Not all applications require cryptographically secure real random number generators. In fact, I'd argue that most random usage is not for that sort of thing. It will be used in tutorials, or in games for a purpose such as selecting between several available sounds. Or procedural generation if it doesn't totally suck.

If you *are* writing something that really requires a better quality pseudorandom generator, odds are that you will have to import one anyway.

I have no idea of what rand() uses internally, and much less what is Chicken is actually calling on Win32. So one thing that could be of value is not relying on the OS implementation and instead providing our own (Mersenne Twister?). This would remove a core dependency and guarantee consistency when running on all operating systems. Even if it is consistently crappy(which MT doesn't appear to be, even if it should not be used for crypto). That would be preferable, so you'd deal with it in the beginning, instead of when porting to another OS, when you've already forgotten all about the random generator.

For reference:
(random N) procedure

Returns a pseudo-random integer in [0, N-1]. N is an integer.

On Windows, N and the random value are exact integer.

Warning: This procedure uses rand(3) internally and exhibits its deficiencies, including low quality pseudo-randomness:

  • On Windows and Solaris, only 32768 unique random values can be generated in the range [0, N-1]. If N >= 32768, there will be gaps in the result set.
  • On Mac OS X, Windows and some other platforms, little variance in output is seen with nearby seeds. Since the random generator is seeded with current-seconds at startup, new processes may see similar or identical random sequences for up to a minute.
  • On Linux, rand(3) is an alias to random(3), which provides output of reasonable quality.

— Stephen



reply via email to

[Prev in Thread] Current Thread [Next in Thread]