ChaosPro Home
Introduction
What's New
Palettes
Using Formulas
Layering in ChaosPro
Rendering
Fractal Parameter Windows
Windows
Menu
3D Transformations
Animations
Formula Compiler
Writing Formulas
Language Reference
Introduction
Basic Syntax
Datatypes
Constants
Variables
Expressions
Operators
Functions
Arithmetic
Conversion
Color
Trigonometric
Miscellaneous
ident
isFinite
isNaN
oldz
perlinNoise
perlinNoise3
random
random.real
srand
trafoHistory
ubound
zero
Control Structures
Compiler Directives
Functions
Interface to ChaosPro
Special Features, Notes...
Compatibility
Fractal Type Reference
Tutorials
Appendix
CHAOSPRO 4.0
Release 4.0
.

Predefined Functions - random

Function name:random - Generate random number
Synopsis:random(x)

Input data type Output data type
real or int int


Description:

The random function returns a pseudorandom integer ranging from -randomrange upto randomrange-1.

It takes the input value as seed used to generate a random number. Within the same version of ChaosPro the same seed value will always generate the same random number.

So in order to generate a sequence of random numbers, you must change the input value for the function. This can be most easily done by using the random number from the previous call as the input value for the next call:

r=random(p);
for (i=0;i<100;i=i+1)
{
   r=random(r); // use the random number from the previous call as seed for the new call...
   // do something with r
}
Examples
  • In order to get a random number between 0 and 1, use abs(random(x))/randomrange
  • In order to get a random number between 0 and n, use random(x) % (n+1)