org.apache.hama.util
Class RandomVariable

java.lang.Object
  extended by org.apache.hama.util.RandomVariable

public class RandomVariable
extends Object

The RandomVaraibale Class provides static methods for generating random numbers.


Constructor Summary
RandomVariable()
           
 
Method Summary
static double beta(double a, double b)
          Generate a random number from a beta random variable.
static double cauchy(double mu, double sigma)
          Generate a random number from a Cauchy random variable (Mean = Inf, and Variance = Inf).
static double chi2(int n)
          Generate a random number from a Chi-2 random variable.
static double dirac(double[] values, double[] prob)
          Generate a random number from a discrete random variable.
static double exponential(double lambda)
          Generate a random number from an exponantial random variable (Mean = 1/lambda, variance = 1/lambda^2).
static double logNormal(double mu, double sigma)
          Generate a random number from a LogNormal random variable.
static double normal(double mu, double sigma)
          Generate a random number from a Gaussian (Normal) random variable.
static double rand()
          Generate a random number between 0 and 1.
static int randInt(int i0, int i1)
          Generate a random integer.
static String randString(String prefix, int length)
          Generate a random string using the specified prefix and a fixed length.
static double triangular(double min, double max)
          Generate a random number from a symetric triangular random variable.
static double triangular(double min, double med, double max)
          Generate a random number from a non-symetric triangular random variable.
static double uniform(double min, double max)
          Generate a random number from a uniform random variable.
static double weibull(double lambda, double c)
          Generate a random number from a Weibull random variable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomVariable

public RandomVariable()
Method Detail

rand

public static double rand()
Generate a random number between 0 and 1.

Returns:
a double between 0 and 1.

randInt

public static int randInt(int i0,
                          int i1)
Generate a random integer.

Parameters:
i0 - min of the random variable.
i1 - max of the random variable.
Returns:
an int between i0 and i1.

randString

public static String randString(String prefix,
                                int length)
Generate a random string using the specified prefix and a fixed length.

Parameters:
prefix - the specified string prefix.
length - the length of the string to be appended.
Returns:
random string.

uniform

public static double uniform(double min,
                             double max)
Generate a random number from a uniform random variable.

Parameters:
min - min of the random variable.
max - max of the random variable.
Returns:
a double.

dirac

public static double dirac(double[] values,
                           double[] prob)
Generate a random number from a discrete random variable.

Parameters:
values - discrete values.
prob - probability of each value.
Returns:
a double.

normal

public static double normal(double mu,
                            double sigma)
Generate a random number from a Gaussian (Normal) random variable.

Parameters:
mu - mean of the random variable.
sigma - standard deviation of the random variable.
Returns:
a double.

chi2

public static double chi2(int n)
Generate a random number from a Chi-2 random variable.

Parameters:
n - degrees of freedom of the chi2 random variable.
Returns:
a double.

logNormal

public static double logNormal(double mu,
                               double sigma)
Generate a random number from a LogNormal random variable.

Parameters:
mu - mean of the Normal random variable.
sigma - standard deviation of the Normal random variable.
Returns:
a double.

exponential

public static double exponential(double lambda)
Generate a random number from an exponantial random variable (Mean = 1/lambda, variance = 1/lambda^2).

Parameters:
lambda - parmaeter of the exponential random variable.
Returns:
a double.

triangular

public static double triangular(double min,
                                double max)
Generate a random number from a symetric triangular random variable.

Parameters:
min - min of the random variable.
max - max of the random variable.
Returns:
a double.

triangular

public static double triangular(double min,
                                double med,
                                double max)
Generate a random number from a non-symetric triangular random variable.

Parameters:
min - min of the random variable.
med - value of the random variable with max density.
max - max of the random variable.
Returns:
a double.

beta

public static double beta(double a,
                          double b)
Generate a random number from a beta random variable.

Parameters:
a - first parameter of the Beta random variable.
b - second parameter of the Beta random variable.
Returns:
a double.

cauchy

public static double cauchy(double mu,
                            double sigma)
Generate a random number from a Cauchy random variable (Mean = Inf, and Variance = Inf).

Parameters:
mu - median of the Weibull random variable
sigma - second parameter of the Cauchy random variable.
Returns:
a double.

weibull

public static double weibull(double lambda,
                             double c)
Generate a random number from a Weibull random variable.

Parameters:
lambda - first parameter of the Weibull random variable.
c - second parameter of the Weibull random variable.
Returns:
a double.


Copyright © 2011 The Apache Software Foundation