Difference between revisions of "Reference:Rand.inc"

From POV-Wiki
Jump to navigation Jump to search
m (1 revision: Initial Load (TF))
 
m (1 revision: Reference Migration Initial Load)
 
(No difference)

Latest revision as of 19:08, 15 March 2012

A collection of macros for generating random numbers, as well as 4 predefined random number streams: RdmA, RdmB, RdmC, and RdmD. There are macros for creating random numbers in a flat distribution (all numbers equally likely) in various ranges, and a variety of other distributions.

Flat Distributions

SRand(Stream): Signed rand(), returns random numbers in the range [-1, 1].

Parameters:

  • Stream = Random number stream.

RRand(Min, Max, Stream): Returns random numbers in the range [Min, Max].

Parameters:

  • Min = The lower end of the output range.
  • Max = The upper end of the output range.
  • Stream = Random number stream.

VRand(Stream): Returns random vectors in a box from < 0, 0, 0> to < 1, 1, 1>

Parameters:

  • Stream = Random number stream.

VRand_In_Box(PtA, PtB, Stream): Like VRand(), this macro returns a random vector in a box, but this version lets you specify the two corners of the box.

Parameters:

  • PtA = Lower-left-bottom corner of box.
  • PtB = Upper-right-top corner of box.
  • Stream = Random number stream.

VRand_In_Sphere(Stream): Returns a random vector in a unit-radius sphere located at the origin.

Parameters:

  • Stream = Random number stream.

VRand_On_Sphere(Stream): Returns a random vector on the surface of a unit-radius sphere located at the origin.

Parameters:

  • Stream = Random number stream.

VRand_In_Obj(Object, Stream): This macro takes a solid object and returns a random point that is inside it. It does this by randomly sampling the bounding box of the object, and can be quite slow if the object occupies a small percentage of the volume of its bounding box (because it will take more attempts to find a point inside the object). This macro is best used on finite, solid objects (non-solid objects, such as meshes and bezier patches, do not have a defined inside, and will not work).

Parameters:

  • Object = The object the macro chooses the points from.
  • Stream = Random number stream.

Other Distributions

Continuous Symmetric Distributions

Rand_Cauchy(Mu, Sigma, Stream): Cauchy distribution.

Parameters:

  • Mu = Mean.
  • Sigma = Standard deviation.
  • Stream = Random number stream.

Rand_Student(N, Stream): Student's distribution.

Parameters:

  • N = degrees of freedom.
  • Stream = Random number stream.

Rand_Normal(Mu, Sigma, Stream): Normal distribution.

Parameters:

  • Mu = Mean.
  • Sigma = Standard deviation.
  • Stream = Random number stream.

Rand_Gauss(Mu, Sigma, Stream): Gaussian distribution. Like Rand_Normal(), but a bit faster.

Parameters:

  • Mu = Mean.
  • Sigma = Standard deviation.
  • Stream = Random number stream.

Continuous Skewed Distributions

Rand_Spline(Spline, Stream): This macro takes a spline describing the desired distribution. The T value of the spline is the output value, and the .y value its chance of occuring.

Parameters:

  • Spline = A spline determining the distribution.
  • Stream = Random number stream.

Rand_Gamma(Alpha, Beta, Stream): Gamma distribution.

Parameters:

  • Alpha = Shape parameter > 0.
  • Beta = Scale parameter > 0.
  • Stream = Random number stream.

Rand_Beta(Alpha, Beta, Stream): Beta variate.

Parameters:

  • Alpha = Shape Gamma1.
  • Beta = Scale Gamma2.
  • Stream = Random number stream.

Rand_Chi_Square(N, Stream): Chi Square random variate.

Parameters:

  • N = Degrees of freedom (integer).
  • Stream = Random number stream.

Rand_F_Dist(N, M, Stream): F-distribution.

Parameters:

  • N, M = Degrees of freedom.
  • Stream = Random number stream.

Rand_Tri(Min, Max, Mode, Stream): Triangular distribution

Parameters:

  • Min, Max, Mode: Min < Mode < Max.
  • Stream = Random number stream.

Rand_Erlang(Mu, K, Stream): Erlang variate.

Parameters:

  • Mu = Mean >= 0.
  • K = Number of exponential samples.
  • Stream = Random number stream.

Rand_Exp(Lambda, Stream): Exponential distribution.

Parameters:

  • Lambda = rate = 1/mean.
  • Stream = Random number stream.

Rand_Lognormal(Mu, Sigma, Stream): Lognormal distribution.

Parameters:

  • Mu = Mean.
  • Sigma = Standard deviation.
  • Stream = Random number stream.

Rand_Pareto(Alpha, Stream): Pareto distribution.

Parameters:

  • Alpha = ?
  • Stream = Random number stream.

Rand_Weibull(Alpha, Beta, Stream): Weibull distribution.

Parameters:

  • Alpha = ?
  • Beta = ?
  • Stream = Random number stream.

Discrete Distributions

Rand_Bernoulli(P, Stream) and Prob(P, Stream): Bernoulli distribution. Output is true with probability equal to the value of P and false with a probability of 1 - P.

Parameters:

  • P = probability range (0-1).
  • Stream = Random number stream.

Rand_Binomial(N, P, Stream): Binomial distribution.

Parameters:

  • N = Number of trials.
  • P = Probability (0-1)
  • Stream = Random number stream.

Rand_Geo(P, Stream): Geometric distribution.

Parameters:

  • P = Probability (0-1).
  • Stream = Random number stream.

Rand_Poisson(Mu, Stream): Poisson distribution.

Parameters:

  • Mu = Mean.
  • Stream = Random number stream.