next | previous | forward | backward | up | top | index | toc | home

random(Type) -- random element of a type

Synopsis

Description

Synopsis

  • Usage:
    random T
  • Inputs:
  • Outputs:
    • a random instance of the type T
i1 : random RR

o1 = .346961336961373

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

o2 = .406429158631254779983507+.396496861671304146473651*ii

o2 : CC (of precision 80)
i3 : random (ZZ/101)

o3 = -2

      ZZ
o3 : ---
     101
i4 : k = GF 2048

o4 = k

o4 : GaloisField
i5 : VerticalList for i to 5 list random k

     {  9    7    5    4                     }
o5 = { a  + a  + a  + a                      }
     {  10    7    6    5    2               }
     { a   + a  + a  + a  + a  + a           }
     {  8    7    6    4                     }
     { a  + a  + a  + a  + a                 }
     {  10    8    3    2                    }
     { a   + a  + a  + a  + a + 1            }
     {  10    9    8                         }
     { a   + a  + a  + 1                     }
     {  10    9    8    6    5    3    2     }
     { a   + a  + a  + a  + a  + a  + a  + 1 }

o5 : VerticalList

The current value of the variable randomHeight, which can be set by the user, is the upper bound on the absolute values of random integers, and on the absolute values of numerators and denominators of random rational numbers.

i6 : randomHeight

o6 = 10
i7 : for i to 10 list random ZZ

o7 = {8, 9, 0, 3, 3, 3, 7, 0, 3, 6, 3}

o7 : List
i8 : randomHeight = 1000

o8 = 1000
i9 : for i to 10 list random QQ

       32  125  945  271  713  34  7  505  235  93  596
o9 = {---, ---, ---, ---, ---, --, -, ---, ---, --, ---}
      845  641  428  128  648  21  4  198  521  19  371

o9 : List

Synopsis

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

          5       4        3 2       2 3         4      5
o11 = 529x  + 659x y + 757x y  + 755x y  + 984x*y  + 80y

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

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

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

See also