jfcg/rng: compact, fast, sponge-based random number generator

184 views
Skip to first unread message

jfcg...@gmail.com

unread,
May 13, 2022, 7:55:41 PM5/13/22
to golang-nuts
Hi,

jfcg/rng v0.7.0 is just released. It has the following advantages (std=math/rand, alt=golang.org/x/exp/rand):

Effective Entropy (hidden information, in bits):
rng: 128
std: 31
alt: 64

Used memory (in bytes):
rng: 24
std: 4920
alt: 48

Benchmarks:
goos: linux
goarch: amd64
cpu: Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
BenchmarkGet-2       227183912  5.259 ns/op
BenchmarkStdGet-2    267202182  4.497 ns/op
BenchmarkAltGet-2    310959830  3.859 ns/op
BenchmarkExp-2       50470122  23.13  ns/op
BenchmarkStdExp-2    170507682  7.035 ns/op
BenchmarkAltExp-2    162541906  7.387 ns/op
BenchmarkOne-2       228389506  5.248 ns/op
BenchmarkStdOne-2    295455202  4.070 ns/op
BenchmarkAltOne-2    182677640  6.516 ns/op
BenchmarkNormal-2    25363636  46.07  ns/op
BenchmarkStdNormal-2 153550454  7.854 ns/op
BenchmarkAltNormal-2 145823773  8.228 ns/op
BenchmarkTwo-2       228640303  5.243 ns/op

Let me know what you think,
Thanks..

Notes:
- rng tries to be very small & fast
- rng ignores locking by design & compared with lockless std/alt
- rng does not have pseudo-rng yet, just the global one
- rng does not have all API like Perm yet
- rng does not have advanced table-based Exp/Normal like std/alt, hence quite slower for those
- rng.Normal returns two samples, so it is as fast as rng.Exp per sample
- rng is not throughly analized

Questions:
- Can you estimate the length of shortest cycle for rng state?
- Does rng mix bits good enough?

jfcg...@gmail.com

unread,
Jun 21, 2022, 8:01:09 AM6/21/22
to golang-nuts
Hi,

jfcg/rng v1.0 has just been released. Let me know what you think.

Cheers..
Reply all
Reply to author
Forward
0 new messages