## net.i2p.util
Class RandomSource

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

All Implemented Interfaces:
  EntropyHarvester, java.io.Serializable

Direct Known Subclasses:
  BufferedRandomSource, FortunaRandomSource, PooledRandomSource

public class RandomSource
extends java.security.SecureRandom
implements EntropyHarvester

Singleton for whatever PRNG i2p uses.

Author:
  jrandom
See Also:
  Serialized Form

Field Summary
`protected I2PAppContext` `_context`

Fields inherited from class java.security.SecureRandom
``

Constructor Summary
`RandomSource(I2PAppContext context)`

Method Summary
`void` `feedEntropy(java.lang.String source, byte[] data, int offset, int len)` Feed the entropy pools with data[offset:offset+len]
`void` `feedEntropy(java.lang.String source, long data, int bitoffset, int bits)` Feed the entropy pools with the bits in the data
`static RandomSource` `getInstance()`
`EntropyHarvester` `harvester()`
`boolean` `initSeed(byte[] buf)`
`void` `loadSeed()`
`static void` `main(java.lang.String[] args)`
`boolean` `nextBoolean()` override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)
`void` `nextBytes(byte[] buf)` override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)
`double` `nextDouble()` override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)
`float` `nextFloat()` override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)
`double` `nextGaussian()` override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)
`int` `nextInt()` override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)
`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()` override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)
`long` `nextLong(long n)` Like the modified nextInt, nextLong(n) returns a random number from 0 through n, including 0, excluding n.
`void` `saveSeed()`
`static void` `writeSeed(byte[] buf)`

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

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

Field Detail

### _context

    protected I2PAppContext _context

Constructor Detail

### RandomSource

    public RandomSource(I2PAppContext context)

Method Detail

### getInstance

    public static RandomSource getInstance()

### 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.

### nextLong

    public long nextLong(long n)

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

### nextBoolean

    public boolean nextBoolean()

  override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)

### nextBytes

    public void nextBytes(byte[] buf)

  override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)

### nextDouble

    public double nextDouble()

  override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)

### nextFloat

    public float nextFloat()

  override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)

### nextGaussian

    public double nextGaussian()

  override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)

### nextInt

    public int nextInt()

  override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)

### nextLong

    public long nextLong()

  override as synchronized, for those JVMs that don't always pull via nextBytes (cough ibm)

### harvester

    public EntropyHarvester harvester()

### feedEntropy

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

  Description copied from interface: `EntropyHarvester`
  Feed the entropy pools with the bits in the data

  Specified by:
    `feedEntropy` in interface `EntropyHarvester`
  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(java.lang.String source,
                            byte[] data,
                            int offset,
                            int len)

  Description copied from interface: `EntropyHarvester`
  Feed the entropy pools with data[offset:offset+len]

  Specified by:
    `feedEntropy` in interface `EntropyHarvester`
  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

### loadSeed

    public void loadSeed()

### saveSeed

    public void saveSeed()

### writeSeed

    public static final void writeSeed(byte[] buf)

### initSeed

    public final boolean initSeed(byte[] buf)

### main

    public static void main(java.lang.String[] args)