random

random n -- for n an integer, yields a random integer in the range 0 .. n-1.
random x -- for real x, yields a random real number in the range 0 .. x.
random F -- yields a random element of the finite field F.
random(n,R) -- yields a random homogeneous element of degree n in the ring R, where n is an integer or a list of integers.
random(F,G) -- yields a random graded, degree 0, map from the free module G to the free module F.

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 {12 : 0, 14 : 1, 12 : 2, 11 : 3, 8 : 4, 6 : 5, 6 : 6, 6 : 7, 8 : 8, 17 : 9}
     
     o1 : Tally
     
     i2 = R = ZZ/101[t]
     
     o2 = R
     
     o2 : PolynomialRing
     
     i3 = sum(7,i->random 101 * t^i)
     
              6       5       4       3      2
     o3 = 21 t  + 45 t  + 32 t  - 37 t  - 4 t  + 7 t + 34
     
     o3 : R
     
     i4 = R = ZZ/101[x,y]
     
     o4 = R
     
     o4 : PolynomialRing
     
     i5 = random(R^{1,2,3},R^{1,2,3})
     
     o5 = | -5             0       0   |
          | -19x+43y       -37     0   |
          | -6x2+29xy-12y2 27x+45y -35 |
     
                  3       3
     o5 : Matrix R  <--- R
     

Go to main index.

Go to concepts index.