## net.i2p.util
Class FortunaRandomSource

    java.lang.Object
      java.util.Random
          java.security.SecureRandom
              net.i2p.util.RandomSource
                  net.i2p.util.FortunaRandomSource

All Implemented Interfaces:
  Serializable, EntropyHarvester

    public class FortunaRandomSource

extends RandomSource
implements EntropyHarvester

Wrapper around GNU-Crypto's Fortuna PRNG. This seeds from /dev/urandom and ./prngseed.rnd on startup (if they exist), writing a new seed to ./prngseed.rnd on an explicit call to saveSeed().

See Also:
  Serialized Form

Field Summary

Fields inherited from class net.i2p.util.RandomSource
`_context`

Constructor Summary
`FortunaRandomSource(I2PAppContext context)`

Method Summary
`void` `feedEntropy(String source, byte[] data, int offset, int len)` reseed the fortuna
`void` `feedEntropy(String source, long data, int bitoffset, int bits)` reseed the fortuna
`EntropyHarvester` `harvester()`
`protected int` `nextBits(int numBits)` Pull the next numBits of random data off the fortuna instance (returning -2^numBits-1 through 2^numBits-1
`boolean` `nextBoolean()`
`void` `nextBytes(byte[] buf)`
`double` `nextDouble()` Implementation from sun's java.util.Random javadocs
`float` `nextFloat()` Implementation from sun's java.util.Random javadocs
`double` `nextGaussian()` Implementation from sun's java.util.Random javadocs
`int` `nextInt()`
`int` `nextInt(int n)` According to the java docs (http://java.sun.com/j2se/1.4.1/docs/api/java/util/Random.html#nextInt(int)) nextInt(n) should return a number between 0 and n (including 0 and excluding n).
`long` `nextLong()`
`long` `nextLong(long n)` Like the modified nextInt, nextLong(n) returns a random number from 0 through n, including 0, excluding n.
`void` `setSeed(byte[] buf)`

Methods inherited from class net.i2p.util.RandomSource
`getInstance, initSeed, loadSeed, main, saveSeed, writeSeed`

Methods inherited from class java.security.SecureRandom
`generateSeed, getAlgorithm, getInstance, getInstance, getInstance, getProvider, getSeed, next, setSeed`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### FortunaRandomSource

    public FortunaRandomSource(I2PAppContext context)

Method Detail

### setSeed

    public void setSeed(byte[] buf)

  Overrides:
    `setSeed` in class `SecureRandom`

### nextInt

    public int nextInt(int n)

  According to the java docs (http://java.sun.com/j2se/1.4.1/docs/api/java/util/Random.html#nextInt(int)) nextInt(n) should return a number between 0 and n (including 0 and excluding n). However, their pseudocode, as well as sun's, kaffe's, and classpath's implementation INCLUDES NEGATIVE VALUES. WTF. Ok, so we're going to have it return between 0 and n (including 0, excluding n), since thats what it has been used for.

  Overrides:
    `nextInt` in class `RandomSource`

### nextInt

    public int nextInt()

  Overrides:
    `nextInt` in class `Random`

### nextLong

    public long nextLong(long n)

  Like the modified nextInt, nextLong(n) returns a random number from 0 through n, including 0, excluding n.

  Overrides:
    `nextLong` in class `RandomSource`

### nextLong

    public long nextLong()

  Overrides:
    `nextLong` in class `Random`

### nextBoolean

    public boolean nextBoolean()

  Overrides:
    `nextBoolean` in class `Random`

### nextBytes

    public void nextBytes(byte[] buf)

  Overrides:
    `nextBytes` in class `SecureRandom`

### nextDouble

    public double nextDouble()

  Implementation from sun's java.util.Random javadocs

  Overrides:
    `nextDouble` in class `Random`

### nextFloat

    public float nextFloat()

  Implementation from sun's java.util.Random javadocs

  Overrides:
    `nextFloat` in class `Random`

### nextGaussian

    public double nextGaussian()

  Implementation from sun's java.util.Random javadocs

  Overrides:
    `nextGaussian` in class `Random`

### nextBits

    protected int nextBits(int numBits)

  Pull the next numBits of random data off the fortuna instance (returning -2^numBits-1 through 2^numBits-1

### harvester

    public EntropyHarvester harvester()

  Overrides:
    `harvester` in class `RandomSource`

### feedEntropy

    public void feedEntropy(String source,
                            long data,
                            int bitoffset,
                            int bits)

  reseed the fortuna

  Specified by:
    `feedEntropy` in interface `EntropyHarvester`
  Overrides:
    `feedEntropy` in class `RandomSource`
  Parameters:
    `source` - origin of the entropy, allowing the harvester to determine how much to value the data
    `bitoffset` - bit index into the data array to start (using java standard big-endian)
    `bits` - how many bits to use

### feedEntropy

    public void feedEntropy(String source,
                            byte[] data,
                            int offset,
                            int len)

  reseed the fortuna

  Specified by:
    `feedEntropy` in interface `EntropyHarvester`
  Overrides:
    `feedEntropy` in class `RandomSource`
  Parameters:
    `source` - origin of the entropy, allowing the harvester to determine how much to value the data
    `offset` - index into the data array to start
    `len` - how many bytes to use