Return a random integer within a specified range.
value = trand([minimum,] maximum)
Parameters inside the [brackets] are optional.
Call trand to get a random integer that falls within the range specified by the arguments.
It’s a good idea to call srand once to seed the random number generator before using trand. Otherwise, a seed of 1 will be used.
minimum[optional], maximum
These arguments define the range within which falls the random value returned by trand. Whether the range is inclusive of min or max depends on whether these values are negative:
For example:
If only one arg is present, it is max, and min is set to zero.
If max < min, the two arguments are exchanged so that they are in ascending numerical order (then the rules above are applied to the exchanged min and max values).
srand(0)
min = -30
max = 10
for (i = 0; i < 20; i = i + 1) {
randval = trand(min, max)
print(randval)
}
another useful example:
array = { 1, 2, 3, 4, 5, 6, 7 }
len_array = len(array)
for (i = 0; i < 14; i += 1) {
val = array[trand(len_array)]
}
irand, srand, random, rand, pickrand, pickwrand, spray_init, get_spray, maketable(“random”)