chicken-hackers
[Top][All Lists]
Advanced

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

Re: [Chicken-hackers] random numbers for CHICKEN 5


From: lemonboy
Subject: Re: [Chicken-hackers] random numbers for CHICKEN 5
Date: Sat, 4 Nov 2017 10:40:07 +0100
User-agent: NeoMutt/20170113 (1.7.2)

Hello hackers,

Thanks for working on the implementation, Felix!
Here's a few notes I jotted down while going trough the diff.

I believe that the scaling done in `C_random_fixnum` is indeed dangerous as it
may lead to badly-distributed results.
Using a 64bit PRNG with the "proper" reduction procedure (avoid using the
modulo, have a look at OpenBSD `arc4random_uniform`) is, IMO, the way to go: you
can easily reduce a 64bit value to a 32bit one but not the other way around.
A quick search revealed there's a 64bit version of WELL512a [1] but I can't find
any other source on this matter.

If you're not 100% sold on the WELL family I'd suggest to have a look at [2],
this family of PRNG: they are mind-numbingly simple (have a look at the
implementation), produces 64bit numbers, is reasonably fast, has a small state
and is also widely used.

WRT the use of `rand()` to initialize "random_state", I'd use something like
the good old MT19937 initialization sequence with an unpredictable seed,
or, if possible, snatch C_RANDOM_STATE_SIZE bytes worth of entropy from the OS.
On the topic of seeding set-pseudo-random-seed! nor C_set_random_seed check for
empty buffers or negative `n` values. Moreover I think that the input should not
be treated as a circular buffer, you should either give the whole thing or
nothing.

Onto the use of getrandom() now! You have to take into account that there are
two different places you have to look at: the kernel, where the getrandom()
syscall is implemented, and glibc, where the getrandom() procedure is defined.
Right now the check is bogus because it checks for the syscall to be defined and
uses the glibc function (which is defined in /usr/include/linux/random.h),
implementing a tiny `syscall()` wrapper lets users with a old glibc to use this
mechanism.

Have a nice day!
LemonBoy

[1] http://halobates.de/pub/ak/smallsrc/well512.c
[2] http://xoroshiro.di.unimi.it/
[3] https://en.wikipedia.org/wiki/Mersenne_Twister#Initialization



reply via email to

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