[][src]Struct rand::prng::isaac::IsaacCore

pub struct IsaacCore {
    mem: [w<u32>; 256],
    a: w<u32>,
    b: w<u32>,
    c: w<u32>,
}

The core of IsaacRng, used with BlockRng.

Fields

Methods

impl IsaacCore
[src]

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.

Trait Implementations

impl Clone for IsaacCore
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for IsaacCore
[src]

Formats the value using the given formatter. Read more

impl BlockRngCore for IsaacCore
[src]

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.

impl SeedableRng for IsaacCore
[src]

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

Auto Trait Implementations

impl Send for IsaacCore

impl Sync for IsaacCore

Blanket Implementations

impl<R> FromEntropy for R where
    R: SeedableRng
[src]

Creates a new instance, automatically seeded with fresh entropy. Read more

impl<T> ToOwned for T where
    T: Clone
[src]

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

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 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)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Important traits for &'a mut R

Immutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 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)

Performs the conversion.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Important traits for &'a mut R

Mutably borrows from an owned value. Read more

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more