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)

random