9front - general discussion about 9front
 help / color / mirror / Atom feed
* replacing rand()
@ 2016-09-10 10:34 Julius Schmidt
  2016-09-10 12:30 ` [9front] " Julius Schmidt
  0 siblings, 1 reply; 2+ messages in thread
From: Julius Schmidt @ 2016-09-10 10:34 UTC (permalink / raw)
  To: 9front

An infuriating discussion with martian67 this morning has reminded me
to run statistical tests on our rand().  As expected, it doesn't perform
too well (fails 9/15 SmallCrush, BigCrush still running, fails after 256
MB of PractRand).  I'm wondering whether we should replace with rand()
with something better as RNGs exist nowadays that are both simpler,
faster and produce better random numbers.

I would propose xoroshiro128+:

u64int state0, state1;

u64int
llrand(void)
{
 	u64int s0, s1, r;

 	s0 = state0;
 	s1 = state1;
 	r = s0 + s1;
 	s1 ^= s0;
 	state0 = (s0 << 55 | s0 >> 9) ^ s1 ^ (s1 << 14);
 	state1 = (s1 << 36 | s0 >> 28);
 	return r;
}

http://xoroshiro.di.unimi.it/xoroshiro128plus.c


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9front] replacing rand()
  2016-09-10 10:34 replacing rand() Julius Schmidt
@ 2016-09-10 12:30 ` Julius Schmidt
  0 siblings, 0 replies; 2+ messages in thread
From: Julius Schmidt @ 2016-09-10 12:30 UTC (permalink / raw)
  To: 9front

Corrections:

I forgot that lrand() returns bit 31 as zero.  Taking this into account
makes lrand() look pretty good actually.  It passes SmallCrush.  The lower
16 bit fail PractRand (but so does the lowest bit of xoroshiro128+).
The highest 16 bit (30:15) pass PractRand for at least 2 GB (still
running).

Also my code was slightly wrong.
state1 should be s1 >> 28, not s0 >> 28.

On Sat, 10 Sep 2016, Julius Schmidt wrote:

> An infuriating discussion with martian67 this morning has reminded me
> to run statistical tests on our rand().  As expected, it doesn't perform
> too well (fails 9/15 SmallCrush, BigCrush still running, fails after 256
> MB of PractRand).  I'm wondering whether we should replace with rand()
> with something better as RNGs exist nowadays that are both simpler,
> faster and produce better random numbers.
>
> I would propose xoroshiro128+:
>
> u64int state0, state1;
>
> u64int
> llrand(void)
> {
> 	 u64int s0, s1, r;
>
> 	 s0 = state0;
> 	 s1 = state1;
> 	 r = s0 + s1;
> 	 s1 ^= s0;
> 	 state0 = (s0 << 55 | s0 >> 9) ^ s1 ^ (s1 << 14);
> 	 state1 = (s1 << 36 | s0 >> 28);
> 	 return r;
> }
>
> http://xoroshiro.di.unimi.it/xoroshiro128plus.c
>
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-10 12:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-10 10:34 replacing rand() Julius Schmidt
2016-09-10 12:30 ` [9front] " Julius Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).