nodef / extra-random

A random number is a number chosen as if by chance from a set.
https://www.npmjs.com/package/extra-random
MIT License
0 stars 0 forks source link

Psuedo random number generators #5

Open wolfram77 opened 1 year ago

wolfram77 commented 1 year ago

Pseudo random numbers can be generated quickly, when you need a lot of them. May be useful for Procedural generation or Monte Carlo simulation.

haskell/random

High level

RandomGen class

Random class

StdGen class

The are also global variants of the functions.

wolfram77 commented 1 year ago

purescript/purescript-random

wolfram77 commented 1 year ago

ericzhang-cn/random.js

Continuous Distributions

Discrete Distributions

wolfram77 commented 1 year ago

ckknight/random-js

Math.random() produces numbers within [0, 1), but it has different bits of randomness with different engines (min. 32 bits).

Random engines

Provide values within [0, 4294967295], i.e. 32 bits of randomness.

Mersenne Twister class

Random types

wolfram77 commented 1 year ago

jmcvetta/randutil

wolfram77 commented 1 year ago

AndreasMadsen/xorshift

wolfram77 commented 1 year ago

EOSBlox/random

wolfram77 commented 1 year ago

skeeto/rng-js

wolfram77 commented 1 year ago

JuliaRandom/RandomNumbers.jl

PCG Family

Permuted Congruential Generators (PCGs) are a family of RNGs which uses a linear congruential generator as the state-transition function, and uses permutation functions on tuples to produce output that is much more random than the RNG's internal state.

Each PCG generator is available in four variants, based on how it applies the additive constant for its underlying LCG; the variations are:

PCG Method Type:

Mersenne Twisters

The Mersenne Twister is so far the most widely used PRNG. Mersenne Twisters are taken as default random number generators of a great many of software systems, including the Julia language until the current 1.0 version. The most commonly used version of Mersenne Twisters is MT19937, which has a very long period of 2^19937−1 and passes numerous tests including the Diehard tests.

However, it also has many flaws by today's standards. For the large period, MT19937 has to use a 2.5 KiB state buffer, which place a load on the memory caches. More severely, it cannot pass all the TestU01 statistical tests2, and the speed is not so fast. So it is not recommended in most situations.

Random123 Family

Random123 is a library of "counter-based" random number generators (CBRNGs), developed by D.E.Shaw Research1. Counter-based means the RNGs in this family can produce the Nth number by applying a stateless mixing function to the counter N, instead of the conventional approach of using N iterations of a stateful transformation. The current version of Random123 in this package is 1.09, and there are four kinds of RNGs: Threefry, Philox, AESNI, ARS.

Threefry is a non-cryptographic adaptation of the Threefish block cipher from the Skein Hash Function.

Philox uses a Feistel network and integer multiplication.

AESNI uses the Advanced Encryption Standard (AES) New Instruction, available on certain modern x86 processors (some models of Intel Westmere and Sandy Bridge, and AMD Interlagos, as of 2011). AESNI CBRNGs can operate on UInt128 type.

ARS (Advanced Randomization System) is a non-cryptographic simplification of AESNI.

Xorshift Family

Xorshift family is a class of PRNGs based on linear transformation that takes the exclusive or of a number with a bit-shifted version of itself. They are extremely fast on mordern computer architectures, and are very suitable for non-cryptographically-secure use. The suffix -Star and -Plus in the RNG names denote to two classes of improved RNGs23, which make it to pass Big Crush in TestU01. -Star RNGs are obtained by scrambling the output of a normal Xorshift generator with a 64-bit invertible multiplier, while -Plus RNGs return the sum of two consecutive output of a Xorshift generator.

They have a period of 2^64, but not recommended because 64 bits of state are not enough for any serious purpose.

They have a period of 2^128. Xorshift128Plus is presently used in the JavaScript engines of Chrome, Firefox and Safari.

They have a long period of 2^1024, and takes some more space for storing the state. If you are running large-scale parallel simulations, it's a good choice to use Xorshift1024Star.

The successor to Xorshift128 series. They make use of a carefully handcrafted shift/rotate-based linear transformation, resulting in a significant improvement in speed and in statistical quality. Therefore, Xoroshiro128Plus is the current best suggestion for replacing other low-quality generators.

wolfram77 commented 1 year ago

cmcqueen/simplerandom

Most algorithms were obtained from two newsgroup posts by George Marsaglia (mars1). However, some modifications have been made. From (rose1), it seems that the SHR3 algorithm defined in (mars1) is flawed and should not be used. It doesn't actually have a period of 232-1 as expected, but has 64 different cycles, some with very short periods. The SHR3 in the 2003 post is very similar, but with two shift values swapped. It has a period of 232-1 as expected.

We still find KISS from (mars1) useful mainly because it uses 32-bit calculations for MWC, which can be more suitable for small embedded systems. So we define KISS that uses a MWC based on (mars1), but the Cong and SHR3 from (mars2).

From Pierre L'Ecuyer (lecuyer1), the Combined LFSR (Tausworthe) LFSR113 algorithm (lecuyer3) and LFSR88 (aka Taus88) have been implemented.

Random Number Generators Provided

The following pseudo-random number generators are provided:

Generator Notes
MWC1 Two 32-bit MWCs combined. From (mars1).
MWC2 Very similar to MWC1, but slightly modified to improve its statistical properties.
Cong From (mars2).
SHR3 From (mars2).
MWC64 A single 64-bit multiply-with-carry calculation. From (mars2).
KISS Combination of MWC2, Cong and SHR3. Based on (mars1) but using Cong and SHR3 from (mars2), and the modified MWC.
KISS2 Combination of MWC64, Cong and SHR3. From (mars2).
LFSR113 Combined LFSR (Tausworthe) random number generator by L'Ecuyer. From (lecuyer1).
LFSR88 Combined LFSR (Tausworthe) random number generator by L'Ecuyer. From (lecuyer2).
wolfram77 commented 1 year ago

lemire/SIMDxorshift

Please check it out.

wolfram77 commented 1 year ago

sirleech/TrueRandom

wolfram77 commented 1 year ago

leesper/go_rng

Supported Distributions and Functionalities

Usage

wolfram77 commented 1 month ago

Remaining References