Click or drag to resize
StdRandom Class
The StdRandom class provides static methods for generating random number from various discrete and continuous distributions, including Bernoulli, uniform, Gaussian, exponential, pareto, Poisson, and Cauchy. It also provides method for shuffling an array or subarray.
Inheritance Hierarchy
SystemObject
  Algs4NetStdRandom

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public sealed class StdRandom

The StdRandom type exposes the following members.

Properties
  NameDescription
Public propertyStatic memberSeed
The seed of the pseudorandom number generator. Using the same seed enables you to produce the same sequence of "random" number for each execution of the program. Ordinarily, you should set the seed at most once per program.
Top
Methods
  NameDescription
Public methodStatic memberBernoulli
Returns a random boolean from a Bernoulli distribution with success probability 1/2.
Public methodStatic memberBernoulli(Double)
Returns a random boolean from a Bernoulli distribution with success probability P.
Public methodStatic memberCauchy
Returns a random real number from the Cauchy distribution.
Public methodStatic memberDiscrete(Double)
Returns a random integer from the specified discrete distribution.
Public methodStatic memberDiscrete(Int32)
Returns a random integer from the specified discrete distribution.
Public methodStatic memberExp
Returns a random real number from an exponential distribution with rate lambda (λ).
Public methodStatic memberGaussian
Returns a random real number from a standard Gaussian distribution.
Public methodStatic memberGaussian(Double, Double)
Returns a random real number from a Gaussian distribution with mean mu (μ) and standard deviation sigma (σ).
Public methodStatic memberGeometric
Returns a random integer from a geometric distribution with success probability P.
Public methodStatic memberMainTest
Unit test the StdRandom methods
Public methodStatic memberPareto
Returns a random real number from the standard Pareto distribution.
Public methodStatic memberPareto(Double)
Returns a random real number from a Pareto distribution with shape parameter alpha (α).
Public methodStatic memberPoisson
Returns a random integer from a Poisson distribution with mean lambda (λ).
Public methodStatic memberRandom
Returns a random real number uniformly in [0, 1).
Public methodStatic memberShuffle(Double)
Rearranges the elements of the specified array in uniformly random order.
Public methodStatic memberShuffle(Int32)
Rearranges the elements of the specified array in uniformly random order.
Public methodStatic memberShuffle(Object)
Rearranges the elements of the specified array in uniformly random order.
Public methodStatic memberShuffle(Double, Int32, Int32)
Rearranges the elements of the specified subarray in uniformly random order.
Public methodStatic memberShuffle(Int32, Int32, Int32)
Rearranges the elements of the specified subarray in uniformly random order.
Public methodStatic memberShuffle(Object, Int32, Int32)
Rearranges the elements of the specified subarray in uniformly random order.
Public methodStatic memberUniform
Returns a random real number uniformly in [0, 1).
Public methodStatic memberUniform(Int32)
Returns a random integer uniformly in [0, n).
Public methodStatic memberUniform(Double, Double)
Returns a random real number uniformly in [a, b).
Public methodStatic memberUniform(Int32, Int32)
Returns a random integer uniformly in [a, b).
Top
Remarks
For additional documentation, see Section 2.2 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class StdRandom implementation by Robert Sedgewick and Kevin Wayne.

See Also