Package net.i2p.util
Class RandomSource
java.lang.Object
java.util.Random
java.security.SecureRandom
net.i2p.util.RandomSource
- All Implemented Interfaces:
Serializable,java.util.random.RandomGenerator,EntropyHarvester
- Direct Known Subclasses:
FortunaRandomSource
Singleton for whatever PRNG i2p uses.
- Author:
- jrandom
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator
java.util.random.RandomGenerator.ArbitrarilyJumpableGenerator, java.util.random.RandomGenerator.JumpableGenerator, java.util.random.RandomGenerator.LeapableGenerator, java.util.random.RandomGenerator.SplittableGenerator, java.util.random.RandomGenerator.StreamableGenerator -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRandomSource(I2PAppContext context) Deprecated - do not instantiate this directly, as you won't get the good one (Fortuna). -
Method Summary
Modifier and TypeMethodDescriptionvoidfeedEntropy(String source, byte[] data, int offset, int len) Feed the entropy pools with data[offset:offset+len]voidfeedEntropy(String source, long data, int bitoffset, int bits) Feed the entropy pools with the bits in the datastatic RandomSourceSingleton for whatever PRNG i2p uses.final booleaninitSeed(byte[] buf) May block up to 10 secondsvoidloadSeed()May block up to 10 secondsvoidnextBytes(byte[] buf, int offset, int length) Not part of java.util.SecureRandom, but added since Fortuna supports it.intnextInt(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).longnextLong(long n) Like the modified nextInt, nextLong(n) returns a random number from 0 through n, including 0, excluding n.voidsaveSeed()intThis code unused, see FortunaRandomSource overridestatic final voidwriteSeed(byte[] buf) Methods inherited from class java.security.SecureRandom
generateSeed, getAlgorithm, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstanceStrong, getParameters, getProvider, getSeed, next, nextBytes, nextBytes, reseed, reseed, setSeed, setSeed, toStringMethods inherited from class java.util.Random
doubles, doubles, doubles, doubles, from, ints, ints, ints, ints, longs, longs, longs, longs, nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextLongMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.random.RandomGenerator
isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextInt, nextLong
-
Field Details
-
_context
-
-
Constructor Details
-
RandomSource
Deprecated - do not instantiate this directly, as you won't get the good one (Fortuna). Use getInstance() or I2PAppContext.getGlobalContext().random() to get the FortunaRandomSource instance.
-
-
Method Details
-
getInstance
Singleton for whatever PRNG i2p uses. Same as I2PAppContext.getGlobalContext().random(); use context.random() if you have a context already.- Returns:
- I2PAppContext.getGlobalContext().random()
-
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. 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. This code unused, see FortunaRandomSource override -
signedNextInt
public int signedNextInt()This code unused, see FortunaRandomSource override- Returns:
- all possible int values, positive and negative
- Since:
- 0.9.54
-
nextLong
public long nextLong(long n) Like the modified nextInt, nextLong(n) returns a random number from 0 through n, including 0, excluding n. This code unused, see FortunaRandomSource override- Specified by:
nextLongin interfacejava.util.random.RandomGenerator
-
nextBytes
public void nextBytes(byte[] buf, int offset, int length) Not part of java.util.SecureRandom, but added since Fortuna supports it. This code unused, see FortunaRandomSource override- Since:
- 0.8.12
-
harvester
-
feedEntropy
Description copied from interface:EntropyHarvesterFeed the entropy pools with the bits in the data- Specified by:
feedEntropyin interfaceEntropyHarvester- Parameters:
source- origin of the entropy, allowing the harvester to determine how much to value the databitoffset- bit index into the data array to start (using java standard big-endian)bits- how many bits to use
-
feedEntropy
Description copied from interface:EntropyHarvesterFeed the entropy pools with data[offset:offset+len]- Specified by:
feedEntropyin interfaceEntropyHarvester- Parameters:
source- origin of the entropy, allowing the harvester to determine how much to value the dataoffset- index into the data array to startlen- how many bytes to use
-
loadSeed
public void loadSeed()May block up to 10 seconds -
saveSeed
public void saveSeed() -
writeSeed
public static final void writeSeed(byte[] buf) -
initSeed
public final boolean initSeed(byte[] buf) May block up to 10 seconds
-