This is a custom PRNG designed at CrypTools
We'll use the Swift implementation to describe what we're doing
First, let's take a seed for our generator:
var seed = 12
Then let's hash his String
representation:
let hash = String(seed).sha256
Now, we'll take the 10
first characters of the outputed hex digest:
let first = hash.prefix(10)
Now we have a hex
representation of a number in a String
, let's parse it:
let n = Int(first, radix: 16)
Then, we rotate n
like:
let r = (n! >> 13 * seed) % 99371 // for non-swift developers, 'n!' doesn't mean n factorial but the unwrapped value of n
And we change the seed
:
seed = (r ^ n! << 2 + n!) % 70937
Finally we output the absolute value as Float
of r
divided by 99371
to have a number between 0
and 1
:
return Float(abs(r)) / 99371
Language | File |
---|---|
JavaScript | random.js |
Swift | random.swift |
CrypTools didn't created this algorithm, we just found it on the internet
The Blum Blum Shub is a pseudorandom number generator proposed in 1986 by Lenore Blum, Manuel Blum and Michael Shub that is derived from Michael O. Rabin's oblivious transfer mapping.
Blum Blum Shub takes the form:
2
x = x mod M
n+1 n
where M = pq is the product of two large primes p and q.
At each step of the algorithm, some output is derived from x[n+1]; the output is commonly either the bit parity of x[n+1] or one or more of the least significant bits of x[n+1].
The seed x[0] should be an integer that is co-prime to M (i.e. p and q are not factors of x[0]) and not 1 or 0.
The two primes, p and q, should both be congruent to 3 (mod 4) (this guarantees that each quadratic residue has one square root which is also a quadratic residue) and gcd(phi(p - 1), phi(q - 1)) should be small (this makes the cycle length large).
In the implementations, p = 5651 and q = 5623.
Language | File |
---|---|
JavaScript | random.js |
Swift | random.swift |
CrypTools didn't created this algorithm, we just found it on the internet
ISAAC (Indirection, Shift, Accumulate, Add, and Count) generates 32-bit random numbers. Averaged out, it requires 18.75 machine cycles to generate each 32-bit value. Cycles are guaranteed to be at least 2^40
values long, and they are 2^8295
values long on average. The results are uniformly distributed, unbiased, and unpredictable unless you know the seed.
See the complete description here
Language | File |
---|---|
JavaScript | random.js |
C | random.c |
See the pdf
Language | File |
---|---|
JavaScript | random.js |
C | random.c |
Tests are automatically handled by Travis CI.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Arthur Guiot - Initial work & conception - @arguiot
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details