Class 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() seed
      DefaultRandom​(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 consumed
      org.apache.commons.math3.random.RandomGenerator getRandomGenerator()  
      long getSeed()
      Gets the long 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 distributed boolean 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 distributed double value between 0.0 and 1.0 from this random number generator's sequence.
      INDArray nextDouble​(char order, int[] shape)
      Generate a uniform number ndarray of the specified shape and order
      INDArray nextDouble​(char order, long[] shape)  
      INDArray nextDouble​(int[] shape)
      Generate a uniform number ndarray of the specified shape
      INDArray nextDouble​(long[] shape)  
      float nextFloat()
      Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.
      INDArray nextFloat​(char order, int[] shape)
      Generate a uniform number ndarray of the specified shape
      INDArray nextFloat​(char order, long[] shape)  
      INDArray nextFloat​(int[] shape)
      Generate a uniform number ndarray of the specified shape
      INDArray nextFloat​(long[] shape)  
      double nextGaussian()
      Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.
      INDArray nextGaussian​(char order, int[] shape)
      Generate a gaussian number ndarray of the specified shape and order
      INDArray nextGaussian​(char order, long[] shape)  
      INDArray nextGaussian​(int[] shape)
      Generate a gaussian number ndarray of the specified shape
      INDArray nextGaussian​(long[] shape)  
      int nextInt()
      Returns the next pseudorandom, uniformly distributed int 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 distributed long 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 an int seed.
      void setSeed​(int[] seed)
      Sets the seed of the underlying random number generator using an int seed.
      void setSeed​(long seed)
      Sets the seed of the underlying random number generator using a long seed.
      void setStates​(long rootState, long nodeState)  
    • Field Detail

      • randomGenerator

        protected org.apache.commons.math3.random.RandomGenerator randomGenerator
      • seed

        protected long seed
    • Constructor Detail

      • DefaultRandom

        public DefaultRandom()
        Initialize with a System.currentTimeMillis() seed
      • DefaultRandom

        public DefaultRandom​(long seed)
      • DefaultRandom

        public DefaultRandom​(org.apache.commons.math3.random.RandomGenerator randomGenerator)
    • Method Detail

      • setSeed

        public void setSeed​(int seed)
        Description copied from interface: Random
        Sets the seed of the underlying random number generator using an int seed.

        Sequences of values generated starting with the same seeds should be identical.

        Specified by:
        setSeed in interface Random
        Specified by:
        setSeed in interface org.apache.commons.math3.random.RandomGenerator
        Parameters:
        seed - the seed value
      • setSeed

        public void setSeed​(int[] seed)
        Description copied from interface: Random
        Sets the seed of the underlying random number generator using an int seed.

        Sequences of values generated starting with the same seeds should be identical.

        Specified by:
        setSeed in interface Random
        Specified by:
        setSeed in interface org.apache.commons.math3.random.RandomGenerator
        Parameters:
        seed - the seed value
      • setSeed

        public void setSeed​(long seed)
        Description copied from interface: Random
        Sets the seed of the underlying random number generator using a long seed.

        Sequences of values generated starting with the same seeds should be identical.

        Specified by:
        setSeed in interface Random
        Specified by:
        setSeed in interface org.apache.commons.math3.random.RandomGenerator
        Parameters:
        seed - the seed value
      • 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.
        Specified by:
        nextBytes in interface Random
        Specified by:
        nextBytes in interface org.apache.commons.math3.random.RandomGenerator
        Parameters:
        bytes - the non-null byte array in which to put the random bytes
      • nextInt

        public int nextInt()
        Description copied from interface: Random
        Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence. All 232 possible int values should be produced with (approximately) equal probability.
        Specified by:
        nextInt in interface Random
        Specified by:
        nextInt in interface org.apache.commons.math3.random.RandomGenerator
        Returns:
        the next pseudorandom, uniformly distributed int value from this random number generator's sequence
      • 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 interface Random
        Specified by:
        nextInt in interface org.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.
        Specified by:
        nextInt in interface Random
        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).
      • nextLong

        public long nextLong()
        Description copied from interface: Random
        Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence. All 264 possible long values should be produced with (approximately) equal probability.
        Specified by:
        nextLong in interface Random
        Specified by:
        nextLong in interface org.apache.commons.math3.random.RandomGenerator
        Returns:
        the next pseudorandom, uniformly distributed long value from this random number generator's sequence
      • nextBoolean

        public boolean nextBoolean()
        Description copied from interface: Random
        Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
        Specified by:
        nextBoolean in interface Random
        Specified by:
        nextBoolean in interface org.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 distributed float value between 0.0 and 1.0 from this random number generator's sequence.
        Specified by:
        nextFloat in interface Random
        Specified by:
        nextFloat in interface org.apache.commons.math3.random.RandomGenerator
        Returns:
        the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence
      • nextDouble

        public double nextDouble()
        Description copied from interface: Random
        Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.
        Specified by:
        nextDouble in interface Random
        Specified by:
        nextDouble in interface org.apache.commons.math3.random.RandomGenerator
        Returns:
        the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence
      • nextGaussian

        public double nextGaussian()
        Description copied from interface: Random
        Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.
        Specified by:
        nextGaussian in interface Random
        Specified by:
        nextGaussian in interface org.apache.commons.math3.random.RandomGenerator
        Returns:
        the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence
      • nextGaussian

        public INDArray nextGaussian​(int[] shape)
        Description copied from interface: Random
        Generate a gaussian number ndarray of the specified shape
        Specified by:
        nextGaussian in interface Random
        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 interface Random
        Parameters:
        order - the order of the output array
        shape - the shape to generate
        Returns:
        the generated gaussian numbers
      • nextDouble

        public INDArray nextDouble​(int[] shape)
        Description copied from interface: Random
        Generate a uniform number ndarray of the specified shape
        Specified by:
        nextDouble in interface Random
        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 interface Random
        Parameters:
        order - order of the output array
        shape - the shape to generate
        Returns:
        the generated gaussian numbers
      • nextFloat

        public INDArray nextFloat​(int[] shape)
        Description copied from interface: Random
        Generate a uniform number ndarray of the specified shape
        Specified by:
        nextFloat in interface Random
        Parameters:
        shape - the shape to generate
        Returns:
        the generated uniform numbers
      • nextFloat

        public INDArray nextFloat​(char order,
                                  int[] shape)
        Description copied from interface: Random
        Generate a uniform number ndarray of the specified shape
        Specified by:
        nextFloat in interface Random
        shape - the shape to generate
        Returns:
        the generated uniform numbers
      • nextFloat

        public INDArray nextFloat​(char order,
                                  long[] shape)
        Specified by:
        nextFloat in interface Random
      • 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.

        Specified by:
        nextInt in interface Random
        Parameters:
        shape - the shape to generate
        Returns:
        the ndarray with the shape of only integers.
      • 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.

        Specified by:
        nextInt in interface Random
        Parameters:
        n - the max number to generate trod a
        shape - the shape to generate
        Returns:
        the ndarray with the shape of only integers.
      • nextInt

        public INDArray nextInt​(int n,
                                long[] shape)
        Specified by:
        nextInt in interface Random
      • getRandomGenerator

        public org.apache.commons.math3.random.RandomGenerator getRandomGenerator()
      • getSeed

        public long getSeed()
        Description copied from interface: Random
        Gets the long seed of the underlying random number generator.
        Specified by:
        getSeed in interface Random
        Returns:
        the seed value
      • 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 interface Random
        Returns:
      • getPosition

        public long getPosition()
        Description copied from interface: Random
        This method returns number of elements consumed
        Specified by:
        getPosition in interface Random
        Returns:
      • reSeed

        public void reSeed()
        Identical to setSeed(System.currentTimeMillis());
        Specified by:
        reSeed in interface Random
      • reSeed

        public void reSeed​(long seed)
        Identical to setSeed(seed);
        Specified by:
        reSeed in interface Random
        Parameters:
        seed -
      • rootState

        public long rootState()
        Specified by:
        rootState in interface Random
      • nodeState

        public long nodeState()
        Specified by:
        nodeState in interface Random
      • setStates

        public void setStates​(long rootState,
                              long nodeState)
        Specified by:
        setStates in interface Random