Package org.nd4j.linalg.api.rng
Class DefaultRandom
- java.lang.Object
-
- org.nd4j.linalg.api.rng.DefaultRandom
-
- All Implemented Interfaces:
AutoCloseable,org.apache.commons.math3.random.RandomGenerator,Random
public class DefaultRandom extends Object implements Random, org.apache.commons.math3.random.RandomGenerator
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.math3.random.RandomGeneratorrandomGeneratorprotected longseed
-
Constructor Summary
Constructors Constructor Description DefaultRandom()Initialize with a System.currentTimeMillis() seedDefaultRandom(long seed)DefaultRandom(org.apache.commons.math3.random.RandomGenerator randomGenerator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()longgetPosition()This method returns number of elements consumedorg.apache.commons.math3.random.RandomGeneratorgetRandomGenerator()longgetSeed()Gets thelongseed of the underlying random number generator.org.bytedeco.javacpp.PointergetStatePointer()This method returns pointer to RNG state structure.booleannextBoolean()Returns the next pseudorandom, uniformly distributedbooleanvalue from this random number generator's sequence.voidnextBytes(byte[] bytes)Generates random bytes and places them into a user-supplied byte array.doublenextDouble()Returns the next pseudorandom, uniformly distributeddoublevalue between0.0and1.0from this random number generator's sequence.INDArraynextDouble(char order, int[] shape)Generate a uniform number ndarray of the specified shape and orderINDArraynextDouble(char order, long[] shape)INDArraynextDouble(int[] shape)Generate a uniform number ndarray of the specified shapeINDArraynextDouble(long[] shape)floatnextFloat()Returns the next pseudorandom, uniformly distributedfloatvalue between0.0and1.0from this random number generator's sequence.INDArraynextFloat(char order, int[] shape)Generate a uniform number ndarray of the specified shapeINDArraynextFloat(char order, long[] shape)INDArraynextFloat(int[] shape)Generate a uniform number ndarray of the specified shapeINDArraynextFloat(long[] shape)doublenextGaussian()Returns the next pseudorandom, Gaussian ("normally") distributeddoublevalue with mean0.0and standard deviation1.0from this random number generator's sequence.INDArraynextGaussian(char order, int[] shape)Generate a gaussian number ndarray of the specified shape and orderINDArraynextGaussian(char order, long[] shape)INDArraynextGaussian(int[] shape)Generate a gaussian number ndarray of the specified shapeINDArraynextGaussian(long[] shape)intnextInt()Returns the next pseudorandom, uniformly distributedintvalue from this random number generator's sequence.intnextInt(int n)Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.INDArraynextInt(int[] shape)Generate a random set of integers of the specified shape.intnextInt(int a, int n)Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.INDArraynextInt(int n, int[] shape)Generate a random set of integers of the specified shape.INDArraynextInt(int n, long[] shape)INDArraynextInt(long[] shape)longnextLong()Returns the next pseudorandom, uniformly distributedlongvalue from this random number generator's sequence.longnodeState()voidreSeed()Identical to setSeed(System.currentTimeMillis());voidreSeed(long seed)Identical to setSeed(seed);longrootState()voidsetSeed(int seed)Sets the seed of the underlying random number generator using anintseed.voidsetSeed(int[] seed)Sets the seed of the underlying random number generator using anintseed.voidsetSeed(long seed)Sets the seed of the underlying random number generator using alongseed.voidsetStates(long rootState, long nodeState)
-
-
-
Method Detail
-
setSeed
public void setSeed(int seed)
Description copied from interface:RandomSets the seed of the underlying random number generator using anintseed.Sequences of values generated starting with the same seeds should be identical.
-
setSeed
public void setSeed(int[] seed)
Description copied from interface:RandomSets the seed of the underlying random number generator using anintseed.Sequences of values generated starting with the same seeds should be identical.
-
setSeed
public void setSeed(long seed)
Description copied from interface:RandomSets the seed of the underlying random number generator using alongseed.Sequences of values generated starting with the same seeds should be identical.
-
nextBytes
public void nextBytes(byte[] bytes)
Description copied from interface:RandomGenerates random bytes and places them into a user-supplied byte array. The number of random bytes produced is equal to the length of the byte array.
-
nextInt
public int nextInt()
Description copied from interface:RandomReturns the next pseudorandom, uniformly distributedintvalue from this random number generator's sequence. All 232 possible int values should be produced with (approximately) equal probability.
-
nextInt
public int nextInt(int n)
Description copied from interface:RandomReturns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.- Specified by:
nextIntin interfaceRandom- Specified by:
nextIntin interfaceorg.apache.commons.math3.random.RandomGenerator- Parameters:
n- the bound on the random number to be returned. Must be positive.- Returns:
- a pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive).
-
nextInt
public int nextInt(int a, int n)Description copied from interface:RandomReturns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
-
nextLong
public long nextLong()
Description copied from interface:RandomReturns the next pseudorandom, uniformly distributedlongvalue from this random number generator's sequence. All 264 possible long values should be produced with (approximately) equal probability.
-
nextBoolean
public boolean nextBoolean()
Description copied from interface:RandomReturns the next pseudorandom, uniformly distributedbooleanvalue from this random number generator's sequence.- Specified by:
nextBooleanin interfaceRandom- Specified by:
nextBooleanin interfaceorg.apache.commons.math3.random.RandomGenerator- Returns:
- the next pseudorandom, uniformly distributed
booleanvalue from this random number generator's sequence
-
nextFloat
public float nextFloat()
Description copied from interface:RandomReturns the next pseudorandom, uniformly distributedfloatvalue between0.0and1.0from this random number generator's sequence.
-
nextDouble
public double nextDouble()
Description copied from interface:RandomReturns the next pseudorandom, uniformly distributeddoublevalue between0.0and1.0from this random number generator's sequence.- Specified by:
nextDoublein interfaceRandom- Specified by:
nextDoublein interfaceorg.apache.commons.math3.random.RandomGenerator- Returns:
- the next pseudorandom, uniformly distributed
doublevalue between0.0and1.0from this random number generator's sequence
-
nextGaussian
public double nextGaussian()
Description copied from interface:RandomReturns the next pseudorandom, Gaussian ("normally") distributeddoublevalue with mean0.0and standard deviation1.0from this random number generator's sequence.- Specified by:
nextGaussianin interfaceRandom- Specified by:
nextGaussianin interfaceorg.apache.commons.math3.random.RandomGenerator- Returns:
- the next pseudorandom, Gaussian ("normally") distributed
doublevalue with mean0.0and standard deviation1.0from this random number generator's sequence
-
nextGaussian
public INDArray nextGaussian(long[] shape)
- Specified by:
nextGaussianin interfaceRandom
-
nextGaussian
public INDArray nextGaussian(int[] shape)
Description copied from interface:RandomGenerate a gaussian number ndarray of the specified shape- Specified by:
nextGaussianin interfaceRandom- Parameters:
shape- the shape to generate- Returns:
- the generated gaussian numbers
-
nextGaussian
public INDArray nextGaussian(char order, int[] shape)
Description copied from interface:RandomGenerate a gaussian number ndarray of the specified shape and order- Specified by:
nextGaussianin interfaceRandom- Parameters:
order- the order of the output arrayshape- the shape to generate- Returns:
- the generated gaussian numbers
-
nextGaussian
public INDArray nextGaussian(char order, long[] shape)
- Specified by:
nextGaussianin interfaceRandom
-
nextDouble
public INDArray nextDouble(long[] shape)
- Specified by:
nextDoublein interfaceRandom
-
nextDouble
public INDArray nextDouble(int[] shape)
Description copied from interface:RandomGenerate a uniform number ndarray of the specified shape- Specified by:
nextDoublein interfaceRandom- Parameters:
shape- the shape to generate- Returns:
- the generated gaussian numbers
-
nextDouble
public INDArray nextDouble(char order, int[] shape)
Description copied from interface:RandomGenerate a uniform number ndarray of the specified shape and order- Specified by:
nextDoublein interfaceRandom- Parameters:
order- order of the output arrayshape- the shape to generate- Returns:
- the generated gaussian numbers
-
nextDouble
public INDArray nextDouble(char order, long[] shape)
- Specified by:
nextDoublein interfaceRandom
-
nextFloat
public INDArray nextFloat(int[] shape)
Description copied from interface:RandomGenerate a uniform number ndarray of the specified shape
-
nextFloat
public INDArray nextFloat(char order, int[] shape)
Description copied from interface:RandomGenerate a uniform number ndarray of the specified shape
-
nextFloat
public INDArray nextFloat(char order, long[] shape)
-
nextInt
public INDArray nextInt(int[] shape)
Description copied from interface:RandomGenerate a random set of integers of the specified shape. Note that these integers will not actually be integers but floats that happen to be whole numbers. The reason for this is due to ints having the same space usage as floats. This also plays nice with blas. If the data opType is set to double, then these will be whole doubles.
-
nextInt
public INDArray nextInt(int n, int[] shape)
Description copied from interface:RandomGenerate a random set of integers of the specified shape. Note that these integers will not actually be integers but floats that happen to be whole numbers. The reason for this is due to ints having the same space usage as floats. This also plays nice with blas. If the data opType is set to double, then these will be whole doubles.
-
getRandomGenerator
public org.apache.commons.math3.random.RandomGenerator getRandomGenerator()
-
getSeed
public long getSeed()
Description copied from interface:RandomGets thelongseed of the underlying random number generator.
-
getStatePointer
public org.bytedeco.javacpp.Pointer getStatePointer()
This method returns pointer to RNG state structure. Please note: DefaultRandom implementation returns NULL here, making it impossible to use with RandomOps- Specified by:
getStatePointerin interfaceRandom- Returns:
-
getPosition
public long getPosition()
Description copied from interface:RandomThis method returns number of elements consumed- Specified by:
getPositionin interfaceRandom- Returns:
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
reSeed
public void reSeed()
Identical to setSeed(System.currentTimeMillis());
-
reSeed
public void reSeed(long seed)
Identical to setSeed(seed);
-
-