trand

Return a random integer within a specified range.


Synopsis

value = trand([minimum,] maximum)

Parameters inside the [brackets] are optional.


Description

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.


Arguments


Examples

   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)]
   }

See Also

irand, srand, random, rand, pickrand, pickwrand, spray_init, get_spray, maketable(“random”)