Random Numbers

Random numbers are available in steve using the command random. The syntax is random[ expression ], where expression is an expression of either int ([link]), float ([link]) or vector ([link]). The value returned is always the same type as the expression. In the case of int or float, the returned value is a random value between 0 and the expression. In the case of a vector expression, the returned value is a vector in which each element is between 0 and the corresponding value of the expression. For example, a call to random[(10, 10, 20)] returns a vector with X and Y elements between 0 and 10, and the Z element between 0 and 20.

Note that random[intValue] returns a value between 0 and intValue, inclusive, as opposed to the behavior that many C programmers expect in which the returned value is between 0 and intValue - 1.

Because many simulations use the origin (0, 0, 0) as the "center" of their world, it is often useful to obtain a random vector centered around (0, 0, 0). For example, if we want to move agents somewhere within an imaginary box surrounding the origin, we might use the expression random[(40, 40, 40)] - (20, 20, 20). This convention gives us a vector with each element between -20 and 20. This type of expression appears frequently in simulations.

The values are produced using the standard C library rand() routine. The library is seeded with the current time when the breve application is launched. To explicitly set the random seed, you may call the internal function randomSeed( value ), where value is an integer.

In the event that multiple breve simulations are launched simultaneously (typically only relevant in cluster environments), it may be necessary to pick unique random seeds for each such simulation to prevent them from producing the exact same results. Refer to the Controller method set-random-seed-from-dev-random for more information on automatically picking unique random seeds on systems that support it.