The core of IsaacRng
, used with BlockRng
.
Create a new ISAAC random number generator.
The author Bob Jenkins describes how to best initialize ISAAC here:
https://rt.cpan.org/Public/Bug/Display.html?id=64324
The answer is included here just in case:
"No, you don't need a full 8192 bits of seed data. Normal key sizes will
do fine, and they should have their expected strength (eg a 40-bit key
will take as much time to brute force as 40-bit keys usually will). You
could fill the remainder with 0, but set the last array element to the
length of the key provided (to distinguish keys that differ only by
different amounts of 0 padding). You do still need to call randinit()
to make sure the initial state isn't uniform-looking."
"After publishing ISAAC, I wanted to limit the key to half the size of
r[]
, and repeat it twice. That would have made it hard to provide a
key that sets the whole internal state to anything convenient. But I'd
already published it."
And his answer to the question "For my code, would repeating the key
over and over to fill 256 integers be a better solution than
zero-filling, or would they essentially be the same?":
"If the seed is under 32 bytes, they're essentially the same, otherwise
repeating the seed would be stronger. randinit() takes a chunk of 32
bytes, mixes it, and combines that with the next 32 bytes, et cetera.
Then loops over all the elements the same way a second time."
Create an ISAAC random number generator using an u64
as seed.
If seed == 0
this will produce the same stream of random numbers as
the reference implementation when used unseeded.
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Results element type, e.g. u32
.
Results type. This is the 'block' an RNG implementing BlockRngCore
generates, which will usually be an array like [u32; 16]
. Read more
Refills the output buffer, results
. See also the pseudocode desciption
of the algorithm in the IsaacRng
documentation.
Optimisations used (similar to the reference implementation):
- The loop is unrolled 4 times, once for every constant of mix().
- The contents of the main loop are moved to a function
rngstep
, to
reduce code duplication.
- We use local variables for a and b, which helps with optimisations.
- We split the main loop in two, one that operates over 0..128 and one
over 128..256. This way we can optimise out the addition and modulus
from
s[i+128 mod 256]
.
- We maintain one index
i
and add m
or m2
as base (m2 for the
s[i+128 mod 256]
), relying on the optimizer to turn it into pointer
arithmetic.
- We fill
results
backwards. The reference implementation reads values
from results
in reverse. We read them in the normal direction, to
make fill_bytes
a memcopy. To maintain compatibility we fill in
reverse.
Seed type, which is restricted to types mutably-dereferencable as u8
arrays (we recommend [u8; N]
for some N
). Read more
Create a new PRNG using the given seed. Read more
Create a new PRNG seeded from another Rng
. Read more
Creates a new instance, automatically seeded with fresh entropy. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static