Package smile.math
Class Random
- java.lang.Object
-
- smile.math.Random
-
public class Random extends java.lang.ObjectThis is a high quality random number generator as a replacement of the standard Random class of Java system.- Author:
- Haifeng Li
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublenextDouble()Generator a random number uniformly distributed in [0, 1).doublenextDouble(double lo, double hi)Generate a uniform random number in the range [lo, hi)voidnextDoubles(double[] d)Generate n uniform random numbers in the range [0, 1)voidnextDoubles(double[] d, double lo, double hi)Generate n uniform random numbers in the range [lo, hi)intnextInt()Returns a random integer.intnextInt(int n)Returns a random integer in [0, n).longnextLong()voidpermutate(double[] x)Generates a permutation of given array.voidpermutate(float[] x)Generates a permutation of given array.int[]permutate(int n)Generates a permutation of 0, 1, 2, ..., n-1, which is useful for sampling without replacement.voidpermutate(int[] x)Generates a permutation of given array.voidpermutate(java.lang.Object[] x)Generates a permutation of given array.voidsetSeed(long seed)Initialize the random generator with a seed.
-
-
-
Method Detail
-
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 rangehi- 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:
lo- lower limit of rangehi- upper limit of ranged- array of random numbers to be generated
-
setSeed
public void setSeed(long seed)
Initialize the random generator with a seed.
-
nextInt
public int nextInt()
Returns a random integer.
-
nextInt
public int nextInt(int n)
Returns a random integer in [0, n).
-
nextLong
public long nextLong()
-
permutate
public int[] permutate(int n)
Generates a permutation of 0, 1, 2, ..., n-1, which is useful for sampling without replacement.
-
permutate
public void permutate(int[] x)
Generates a permutation of given array.
-
permutate
public void permutate(float[] x)
Generates a permutation of given array.
-
permutate
public void permutate(double[] x)
Generates a permutation of given array.
-
permutate
public void permutate(java.lang.Object[] x)
Generates a permutation of given array.
-
-