Package smile.math

Class Random

java.lang.Object
smile.math.Random

public class Random extends Object
This is a high quality random number generator as a replacement of the standard Random class of Java system.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initialize with default random number generator engine.
    Random(long seed)
    Initialize with given seed for default random number generator engine.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Generator a random number uniformly distributed in [0, 1).
    double
    nextDouble(double lo, double hi)
    Generate a uniform random number in the range [lo, hi)
    void
    nextDoubles(double[] d)
    Generate n uniform random numbers in the range [0, 1)
    void
    nextDoubles(double[] d, double lo, double hi)
    Generate n uniform random numbers in the range [lo, hi)
    int
    Returns a random integer.
    int
    nextInt(int n)
    Returns a random integer in [0, n).
    long
    Returns a random long integer.
    void
    permutate(double[] x)
    Permutates an array.
    void
    permutate(float[] x)
    Permutates an array.
    int[]
    permutate(int n)
    Returns a permutation of (0, 1, 2, ..., n-1).
    void
    permutate(int[] x)
    Permutates an array.
    void
    Permutates an array.
    void
    setSeed(long seed)
    Initialize the random generator with a seed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Random

      public Random()
      Initialize with default random number generator engine.
    • Random

      public Random(long seed)
      Initialize with given seed for default random number generator engine.
      Parameters:
      seed - the RNG seed.
  • Method Details

    • setSeed

      public void setSeed(long seed)
      Initialize the random generator with a seed.
      Parameters:
      seed - the RNG seed.
    • nextDouble

      public double nextDouble()
      Generator a random number uniformly distributed in [0, 1).
      Returns:
      a pseudo random number
    • nextDoubles

      public void nextDoubles(double[] d)
      Generate n uniform random numbers in the range [0, 1)
      Parameters:
      d - array of random numbers to be generated
    • nextDouble

      public double nextDouble(double lo, double hi)
      Generate a uniform random number in the range [lo, hi)
      Parameters:
      lo - lower limit of range
      hi - upper limit of range
      Returns:
      a uniform random real in the range [lo, hi)
    • nextDoubles

      public void nextDoubles(double[] d, double lo, double hi)
      Generate n uniform random numbers in the range [lo, hi)
      Parameters:
      d - array of random numbers to be generated
      lo - lower limit of range
      hi - upper limit of range
    • nextInt

      public int nextInt()
      Returns a random integer.
      Returns:
      a random integer.
    • nextInt

      public int nextInt(int n)
      Returns a random integer in [0, n).
      Parameters:
      n - the upper bound of random number.
      Returns:
      a random integer.
    • nextLong

      public long nextLong()
      Returns a random long integer.
      Returns:
      a random long integer.
    • permutate

      public int[] permutate(int n)
      Returns a permutation of (0, 1, 2, ..., n-1).
      Parameters:
      n - the upper bound.
      Returns:
      the permutation of (0, 1, 2, ..., n-1).
    • permutate

      public void permutate(int[] x)
      Permutates an array.
      Parameters:
      x - the array.
    • permutate

      public void permutate(float[] x)
      Permutates an array.
      Parameters:
      x - the array.
    • permutate

      public void permutate(double[] x)
      Permutates an array.
      Parameters:
      x - the array.
    • permutate

      public void permutate(Object[] x)
      Permutates an array.
      Parameters:
      x - the array.