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 R -- yields a random element of the ring R.
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{0 => 11}
           1 => 13
           2 => 8
           3 => 11
           4 => 11
           5 => 7
           6 => 15
           7 => 8
           8 => 8
           9 => 8

o1 : Tally

i2 : R = ZZ/101[t];
i3 : sum(7,i->random 101 * t^i)

        6      5     4     3      2
o3 = 35t  - 19t  + 7t  + 8t  - 19t  + 4t - 8

o3 : R

i4 : R = ZZ/101[x,y];
i5 : random(R^{1,2,3},R^{1,2,3})

o5 = {-1} | 40             0       0  |
     {-2} | -36x+27y       -18     0  |
     {-3} | 33x2-17xy+19y2 21x-28y 22 |

             3       3
o5 : Matrix R  <--- R


topindexpreviousupnext