⚠️ We strongly recommend you to know how to program in at least one programming language
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
Using this explanation, determine what would be the second number outputted using seed = 12
by the HashShift PRNG
- Your answer is composed of the
10
first digits. - We write numbers in the english way, like
3.1415926535
or0.57721566
.