Rand number options - a list?

Hello Chris,

When you get a chance, could you please post the list of options for assigning random numbers with an “assign variable” as well as an explanation of exactly what they are doing? I am aware of:
disc_rand(min, max)
geom_rand(stair_size, max_val)
I’m particularly interested in how draws from the geometric random distribution are determined (I believe there is a normalization stage to adjust for max_val, but I’m not sure what it is).

Thanks,

Nicole

Hi Nicole,

The MWorks expression parser supports three random number functions:

rand([low, high])
disc_rand(low, high)
geom_rand(Bernoulli_prob, high)

The first function, rand, returns a random floating-point value uniformly distributed in the range [low…high). If called without any parameters (e.g. rand()), low and high default to 0.0 and 1.0, respectively. (See boost::uniform_real.)

The second function, disc_rand, returns a random integer value uniformly distributed in the set of integer numbers {min, min+1, min+2, …, max}. (See boost::uniform_int.)

The third function, geom_rand, returns a discrete random number sampled in the interval [0, high] from a geometric distribution with constant Bernoulli probability Bernoulli_prob. The comments in the code say it uses a Monte Carlo sampling algorithm taken from Rubinstein. The value is computed by the following code, where uni() is equivalent to rand():

do {
    value = floor( log( uni() ) / log( 1-Bernoulli_prob ) );
} while ( value > high );

If you need more info, please let me know.

Chris

Hi Nicole,

as you know I implemented that function.

I can only add that, since “high” is the largest value that the
sampled integer can take, the distribution is obviously not truly
geometrical (otherwise it should allow sampled values up to
+infinity). Therefore, the distribution is actually a truncated (to
high) and re-normalized geometrical distribution. The renormalization
simply means that in the interval [0 high] the probability to sample
each integer is slightly higher than for a real geom. distribution, to
take into account that all integer values > high are not allowed.

I hope it can help
davide

Great - thanks to you both!

As a related reference, I see that Elias and Chris have a nice list of other functions (cos, tan, log) posted under the “Suggestions” thread.

Nicole