Monday, January 13, 2025

SplitMix64

 


If you need a PRNG to generate very very very big integers, the SplitMix64Random package is what you need! Compatible with Squeak 6.0.

It's a well-known fact that PRNGs using floats internally show gaps when generating ultra big integers : the precision of floats being finite, there are big numbers they will never be able to generate.

So here's an implementation of the SplitMix64 pseudo-random number generator. It is very fast, has a period of 2^64 and passes the Big Crush, DieHard and TestU012 standard statistical test suites.

However, the SplitMix64 PRNG should NOT be used for cryptographic or security applications!

It is adequate for everyday use, such as Monte Carlo algorithms and randomized data where speed is essential. It is also efficient at dealing with very large random integer values as it circumvents the problem induced by floats having limited precision thus creating gaps between the possible large integers that could theoretically be generated.

Originally created by Sebasto Vigna, SplitMix64 is based on SplittableRandom in Java 8.

Useful references : 

http://xorshift.di.unimi.it/splitmix64.c

https://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html

https://github.com/lemire/testingRNG 

P.S. As a quick-and-dirty visual verification, you can use the following code in a workspace to generate an image similar to the one at the top of this post:

"
VISUAL analysis of a Random Number Generator


References:
https://www.random.org/analysis/
https://boallen.com/random-numbers.html
"

| form colors yourFavoriteRNG size |

size := 512.
yourFavoriteRNG := Random new.

colors := Array with: Color white with: Color black.
form := Form extent: size@size depth: 32.

0 to: (size-1) do: [ :x |
    0 to: (size-1) do: [ :y | form colorAt: (x@y) put: (colors atRandom: yourFavoriteRNG) ] ].
PNGReadWriter putForm: form onFileNamed: 'test.png'.

Below is the image generated with the infamous PHP pseudo-random number generator:

2 comments: