next | previous | forward | backward | up | top | index | toc | directory | Macaulay 2 web site

random(Type) -- random element of a type

Synopsis

Description

Synopsis

  • Usage:
    random T
  • Inputs:
  • Outputs:
    • a random instance of the type T. If the Height option specifies a number h and T is ZZ and , then the integers returned are in the range 0 .. h-1; for QQ the numerator and denominator are in the range 1 .. h.
i1 : random RR

o1 = .346961336961373

o1 : RR (of precision 53)
i2 : random CC_100

o2 = .0809593725498833597244822373574+.121086033468111758774448742186*ii

o2 : CC (of precision 100)
i3 : tally for i to 100 list random GF 11

o3 = Tally{-1 => 9 }
           -2 => 5
           -3 => 12
           -4 => 9
           -5 => 11
           0 => 10
           1 => 3
           2 => 9
           3 => 16
           4 => 7
           5 => 10

o3 : Tally
i4 : random GF(2,40)

      39    38    36    34    32    31    30    29    27    25    24    23  
o4 = a   + a   + a   + a   + a   + a   + a   + a   + a   + a   + a   + a   +
     ------------------------------------------------------------------------
      22    21    15    12    11    9    7    6    4
     a   + a   + a   + a   + a   + a  + a  + a  + a

o4 : GF 1099511627776

Synopsis

  • Usage:
    random(d,R)
  • Inputs:
  • Outputs:
    • a random homogeneous element of the ring R of degree d
i5 : R = ZZ[x,y];
i6 : random(5,R)

       5     4      3 2    2 3       4     5
o6 = 3x  + 7x y + 6x y  + x y  + 6x*y  + 3y

o6 : R
i7 : R = GF(25,Variable=>a)[x,y];
i8 : VerticalList for i to 6 list random(3,R)

     {   3           2                 2      3               }
o8 = {a*x  + (a + 1)x y + (- 2a - 2)x*y  - a*y                }
     {         2               2     3                        }
     {(2a + 1)x y + (2a + 1)x*y  + 2y                         }
     {          3      2          2              3            }
     {(- a - 1)x  + a*x y - 2a*x*y  + (- 2a + 2)y             }
     { 3             2                2      3                }
     {x  + (- a + 2)x y + (- a + 1)x*y  + a*y                 }
     {      3       2          2            3                 }
     {- 2a*x  - 2a*x y + 2a*x*y  + (2a + 1)y                  }
     {           3             2              2              3}
     {(- 2a + 2)x  + (- a - 1)x y + (a + 2)x*y  + (- 2a - 2)y }
     {     3            2        2            3               }
     {- a*x  + (2a - 2)x y - 2x*y  + (2a - 2)y                }

o8 : VerticalList
The length of d, if it's a list, should be the same as degreeLength R.

See also