Home page  
Help >
Random Functions
Version 7.11
Random Functions

The RAND function is used to generate uniform random numbers.

calc %result= rand(seed)-First time call
calc %result= rand(0)-All subsequent calls

The "seed" can be a fieldname, variable, or literal and is any arbitrary number you pick.

Once you have "seeded" the RAND function, all subsequent calls used to generate a sequence of random numbers should just send in 0 (zero) as the argument. More about that below.

The result is always a number between zero and one. So if, for example, you want to generate random numbers between one and ten thousand you need to multiply the result of the RAND function by 10000. Then take the integer portion of the result (found in the %answercell) as your number.

calc %n=rand(0)*10000 -gets random number0<=%n<=10000
calc %n=rand(0)*100000 -gets random number0<=%n<=100000
calc %n=rand(0)*1000000 -gets random number0<=%n<=1000000
calc %n=rand(0)*N -gets random number0<=%n<=N

A common misconception made by people using random number generators is to send in a seed with every call. Unless you really know what you are doing, this is generally a mistake and you will not get a truly uniform distribution of random numbers. So the thing to do is to seed it once, then use the zero argument all the rest of the time for any given session; that is, let the RAND function do its thing. It is really amazing how good it is at generating a truly random distribution.

Another thing about good random functions is that if you start tomorrow with the same seed that you used today you will get exactly the same sequence of random numbers. This is good for people who are looking for repeatability in testing but can be bad for other applications. So what some people do to insure that they never use the same seed again is to compute a seed based upon date and time.


Non Uniform Random

The non-uniform random function, NURAND, uses RAND internally as part of it's calculation so the assumption is that RAND has already been seeded in this session.

calc %nu=nurand(arg;x;y)

This generates a non-uniformally distributed random number between the range of X and Y. That is,x<=%nu<=y, and the distribution of %nu is non uniform.

With this function you always send the same numbers with each call, there is no "first time" consideration.

Arg is a constant that is arbitrary. It determines the "humps" in the non uniformity. Generally the larger the range of [x..y] the larger Arg is. Here is a table that will give you an idea of typical values to pick for Arg.

For XY ranges 1..1000 pick Arg <=255
For XY ranges 1..10000 pick Arg <=1023
For XY ranges 1..100000 pick Arg <=8191
For XY ranges 1..1000000 pick Arg <=32767

Copyright © 2019 , WhamTech, Inc.  All rights reserved. This document is provided for information purposes only and the contents hereof are subject to change without notice. Names may be trademarks of their respective owners.