9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Julius Schmidt <aiju@phicode.de>
To: 9front@9front.org
Subject: replacing rand()
Date: Sat, 10 Sep 2016 12:34:58 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LNX.2.00.1609101118350.6016@phi> (raw)

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


             reply	other threads:[~2016-09-10 10:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-10 10:34 Julius Schmidt [this message]
2016-09-10 12:30 ` [9front] " Julius Schmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.00.1609101118350.6016@phi \
    --to=aiju@phicode.de \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).