pickwrand

Return a weighted random choice from a set of numbers.


Synopsis

value = pickwrand(number1, probability1 [, number2, probability2, … numberN, probabilityN ])

Parameters inside the [brackets] are optional.


Description

Call pickwrand to choose randomly among several numbers that you specify, with a probability for each number.

It’s a good idea to call srand once to seed the random number generator before using pickwrand. Otherwise, a seed of 1 will be used.


Arguments


RETURN VALUE

One of the number arguments to pickwrand, selected randomly in accordance with the given probabilities.


Examples

   srand(0)
   while (outskip < ending_time) {
      stereo_loc = pickwrand(0.0, 10,  0.5, 80,  1.0, 10)
      WAVETABLE(outskip, dur, amp, frequency, stereo_loc)
      outskip = outskip + 0.2
   }

plays WAVETABLE notes, panning them in accordance with the following probabilities: 10% of the notes will pan to hard left, 10% of the notes will pan to hard right, and 80% of the notes will pan to the center.


See Also

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