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.RandomGenerator
randomGenerator
protected long
seed
-
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 void
close()
long
getPosition()
This method returns number of elements consumedorg.apache.commons.math3.random.RandomGenerator
getRandomGenerator()
long
getSeed()
Gets thelong
seed of the underlying random number generator.org.bytedeco.javacpp.Pointer
getStatePointer()
This method returns pointer to RNG state structure.boolean
nextBoolean()
Returns the next pseudorandom, uniformly distributedboolean
value from this random number generator's sequence.void
nextBytes(byte[] bytes)
Generates random bytes and places them into a user-supplied byte array.double
nextDouble()
Returns the next pseudorandom, uniformly distributeddouble
value between0.0
and1.0
from this random number generator's sequence.INDArray
nextDouble(char order, int[] shape)
Generate a uniform number ndarray of the specified shape and orderINDArray
nextDouble(char order, long[] shape)
INDArray
nextDouble(int[] shape)
Generate a uniform number ndarray of the specified shapeINDArray
nextDouble(long[] shape)
float
nextFloat()
Returns the next pseudorandom, uniformly distributedfloat
value between0.0
and1.0
from this random number generator's sequence.INDArray
nextFloat(char order, int[] shape)
Generate a uniform number ndarray of the specified shapeINDArray
nextFloat(char order, long[] shape)
INDArray
nextFloat(int[] shape)
Generate a uniform number ndarray of the specified shapeINDArray
nextFloat(long[] shape)
double
nextGaussian()
Returns the next pseudorandom, Gaussian ("normally") distributeddouble
value with mean0.0
and standard deviation1.0
from this random number generator's sequence.INDArray
nextGaussian(char order, int[] shape)
Generate a gaussian number ndarray of the specified shape and orderINDArray
nextGaussian(char order, long[] shape)
INDArray
nextGaussian(int[] shape)
Generate a gaussian number ndarray of the specified shapeINDArray
nextGaussian(long[] shape)
int
nextInt()
Returns the next pseudorandom, uniformly distributedint
value from this random number generator's sequence.int
nextInt(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.INDArray
nextInt(int[] shape)
Generate a random set of integers of the specified shape.int
nextInt(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.INDArray
nextInt(int n, int[] shape)
Generate a random set of integers of the specified shape.INDArray
nextInt(int n, long[] shape)
INDArray
nextInt(long[] shape)
long
nextLong()
Returns the next pseudorandom, uniformly distributedlong
value from this random number generator's sequence.long
nodeState()
void
reSeed()
Identical to setSeed(System.currentTimeMillis());void
reSeed(long seed)
Identical to setSeed(seed);long
rootState()
void
setSeed(int seed)
Sets the seed of the underlying random number generator using anint
seed.void
setSeed(int[] seed)
Sets the seed of the underlying random number generator using anint
seed.void
setSeed(long seed)
Sets the seed of the underlying random number generator using along
seed.void
setStates(long rootState, long nodeState)
-
-
-
Method Detail
-
setSeed
public void setSeed(int seed)
Description copied from interface:Random
Sets the seed of the underlying random number generator using anint
seed.Sequences of values generated starting with the same seeds should be identical.
-
setSeed
public void setSeed(int[] seed)
Description copied from interface:Random
Sets the seed of the underlying random number generator using anint
seed.Sequences of values generated starting with the same seeds should be identical.
-
setSeed
public void setSeed(long seed)
Description copied from interface:Random
Sets the seed of the underlying random number generator using along
seed.Sequences of values generated starting with the same seeds should be identical.
-
nextBytes
public void nextBytes(byte[] bytes)
Description copied from interface:Random
Generates 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:Random
Returns the next pseudorandom, uniformly distributedint
value 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:Random
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.- Specified by:
nextInt
in interfaceRandom
- Specified by:
nextInt
in 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:Random
Returns 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:Random
Returns the next pseudorandom, uniformly distributedlong
value 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:Random
Returns the next pseudorandom, uniformly distributedboolean
value from this random number generator's sequence.- Specified by:
nextBoolean
in interfaceRandom
- Specified by:
nextBoolean
in interfaceorg.apache.commons.math3.random.RandomGenerator
- Returns:
- the next pseudorandom, uniformly distributed
boolean
value from this random number generator's sequence
-
nextFloat
public float nextFloat()
Description copied from interface:Random
Returns the next pseudorandom, uniformly distributedfloat
value between0.0
and1.0
from this random number generator's sequence.
-
nextDouble
public double nextDouble()
Description copied from interface:Random
Returns the next pseudorandom, uniformly distributeddouble
value between0.0
and1.0
from this random number generator's sequence.- Specified by:
nextDouble
in interfaceRandom
- Specified by:
nextDouble
in interfaceorg.apache.commons.math3.random.RandomGenerator
- Returns:
- the next pseudorandom, uniformly distributed
double
value between0.0
and1.0
from this random number generator's sequence
-
nextGaussian
public double nextGaussian()
Description copied from interface:Random
Returns the next pseudorandom, Gaussian ("normally") distributeddouble
value with mean0.0
and standard deviation1.0
from this random number generator's sequence.- Specified by:
nextGaussian
in interfaceRandom
- Specified by:
nextGaussian
in interfaceorg.apache.commons.math3.random.RandomGenerator
- Returns:
- the next pseudorandom, Gaussian ("normally") distributed
double
value with mean0.0
and standard deviation1.0
from this random number generator's sequence
-
nextGaussian
public INDArray nextGaussian(long[] shape)
- Specified by:
nextGaussian
in interfaceRandom
-
nextGaussian
public INDArray nextGaussian(int[] shape)
Description copied from interface:Random
Generate a gaussian number ndarray of the specified shape- Specified by:
nextGaussian
in interfaceRandom
- Parameters:
shape
- the shape to generate- Returns:
- the generated gaussian numbers
-
nextGaussian
public INDArray nextGaussian(char order, int[] shape)
Description copied from interface:Random
Generate a gaussian number ndarray of the specified shape and order- Specified by:
nextGaussian
in 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:
nextGaussian
in interfaceRandom
-
nextDouble
public INDArray nextDouble(long[] shape)
- Specified by:
nextDouble
in interfaceRandom
-
nextDouble
public INDArray nextDouble(int[] shape)
Description copied from interface:Random
Generate a uniform number ndarray of the specified shape- Specified by:
nextDouble
in interfaceRandom
- Parameters:
shape
- the shape to generate- Returns:
- the generated gaussian numbers
-
nextDouble
public INDArray nextDouble(char order, int[] shape)
Description copied from interface:Random
Generate a uniform number ndarray of the specified shape and order- Specified by:
nextDouble
in 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:
nextDouble
in interfaceRandom
-
nextFloat
public INDArray nextFloat(int[] shape)
Description copied from interface:Random
Generate a uniform number ndarray of the specified shape
-
nextFloat
public INDArray nextFloat(char order, int[] shape)
Description copied from interface:Random
Generate 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:Random
Generate 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:Random
Generate 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:Random
Gets thelong
seed 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:
getStatePointer
in interfaceRandom
- Returns:
-
getPosition
public long getPosition()
Description copied from interface:Random
This method returns number of elements consumed- Specified by:
getPosition
in interfaceRandom
- Returns:
-
close
public void close() throws Exception
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
reSeed
public void reSeed()
Identical to setSeed(System.currentTimeMillis());
-
reSeed
public void reSeed(long seed)
Identical to setSeed(seed);
-
-