[top][index]
search for:

random ZZ -- random integer

Synopsis:

  • Function: random -- get a random element
  • Input:
  • an instance of class ZZ.
  • Output:
  • an instance of class ZZ.
  • 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

    See also:

  • setRandomSeed -- set starting point for random number generator
  • Code:

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

    [top][index]
    search for: