[next][previous][up][top][index]
search for:

random ZZ -- random integer

random n -- yields a random integer in the range 0 .. n-1.

Warning: doesn't correctly handle the case when n an integer is larger than 2^31-1.

i1 : tally apply(100, i -> random 10)

o1 = Tally{0 => 11}
           1 => 13
           2 => 8
           3 => 11
           4 => 11
           5 => 7
           6 => 15
           7 => 8
           8 => 8
           9 => 8

o1 : Tally

Synopsis of use:

  • Operator: random
  • Class of argument 1: ZZ
  • Class of typical returned value: ZZ
  • Code:

         -- ../m2/integers.m2:62-64
         random ZZ := ZZ => x -> (
              if x <= 0 then error "expected a positive number";
              randomint() % x)

    [next][previous][up][top][index]
    search for: