Random

Revision as of 04:55, 13 January 2016 by Bbecane (talk | contribs)


Random(dist, method, over)

Function Random generates a single random value from a probability distribution. It is not a probability distribution per se, such as Normal() or Uniform(). It generates a single value, not a sample indexed by Run, and it does so whether evaluated in a deterministic (Mid) or probabilistic context. For example.

Random(Normal(10, 2))

generates a single value generated at random from the specified Normal distribution.

Random()

with no parameters, it returns a single uniformly-distributed random number between 0 and 1.

Declaration

Random(dist: Optional Unevaluated; method: Optional Scalar; over: ... Optional Index)

Parameters:

  • «dist» : If specified, must be an explicit call to a distribution function that supports single-sample generation (see below). If you specify no distribution, it defaults to Uniform(0,1). If dist is a multivariate distribution, indexed by I, it truents
  • «method»: Selects the algorithm used to generate the random number. Possible value are: 0=use system default, 1=Minimal standard, 2=L'Ecuyer, 3=Knuth.
  • «over»: A convenient way to list indexes that independent random numbers will be generated over. (This will also occur if the index(es) occur in any of the other parameters).

Description

Random is not a distribution-function per-se, as Uniform(0,1) is. However, one often needs access to a random number generator stream, such as for rejection sampling, Metropolis-Hastings simulation, etc. Random() makes it possible to get such values, even if the global sampling method is Latin hypercube, and efficiently since it isn't necessary to generate an entire sample. Random can return variates from a wide variety of distributions. It is even possible to write user-defined distribution functions for custom distributions that work with random.

Examples

Random(Uniform(-100, 100)) Returns a single real-valued random number uniformly selected between -100 and 100.
Random(Uniform(1, 100, integer: True)): Returns a random integer between 1 and 100 inclusive.
Random(Over: I): Returns an array of independent uniform random numbers between 0 and 1 indexed by I.  The numbers are independent (i.e., Monte Carlo sampled, never Latin Hypercube).
Random(Over: I, J): Returns a 2-D array of independent uniform random numbers between 0 and 1, indexed by I and J.  All numbers in the array are sampled independently.
Random(Uniform(min: Array(I, J, 0), max: 1)): This is functionally equivalent to the preceding example. It demonstrates how the Over parameter is only a convenience, but results in an easier to interpret syntax.

Distribution Function Support for Single Samples

Random supports only those distribution functions with parameter singleMethod, usually declared as:

singleSampleMethod: Optional Atomic Numeric

When the parameter is provided, the distribution function must return a single random variate from the distribution indicated by the other parameters. Random will fill in this parameter with one of the following values, indicating which sampling method should be used:

Possible values for singleMethod:
0 = use default method
1 = use Minimal standard
2 = use L'Ecuyer
3 = use Knuth

As an example, consider what happens when Random(Normal(2, 3)) is evaluated. The Random function checks that its parameter is an acceptable distribution function, and then it evaluates:

Normal(2, 3, singleSampleMethod: 0)

Random(dist) supports any of these built-in probability distributions functions as the distribution:

It also works for these distributions from the Distribution variations library:

It also works for these distributions from the Multivariate Distributions library:

Random does not support these built-in distribution functions:

User-defined functions can support single-variate generation, and therefore can be used as a parameter to Random, if they have a parameter named singleMethod.

See Also

Comments


You are not allowed to post comments.