Macaulay2 » Documentation
Packages » Macaulay2Doc » combinatorics » random » randomSubset
next | previous | forward | backward | up | index | toc

randomSubset

Description

When n is given, then a random subset x of cardinality n is returned.

i1 : randomSubset({2, 3, 5, 7, 11}, 2)

o1 = {3, 5}

o1 : List

Otherwise, a random subset of arbitrary cardinality is returned.

i2 : randomSubset {2, 3, 5, 7, 11}

o2 = {7}

o2 : List
i3 : randomSubset {2, 3, 5, 7, 11}

o3 = {2, 5, 7, 11}

o3 : List
i4 : randomSubset {2, 3, 5, 7, 11}

o4 = {2, 3, 5, 7}

o4 : List

If x is an integer, then a subset of $\{0,\ldots,x - 1\}$ is returned.

i5 : randomSubset(4, 2)

o5 = {0, 1}

o5 : List
i6 : randomSubset 5

o6 = {1}

o6 : List

References

Knuth, Donald E. The Art of Computer Programming: Seminumerical Algorithms, Volume 2. Addison-Wesley Professional, 2014. (Algorithm S, Section 3.4.2)

See also

Ways to use randomSubset:

  • randomSubset(Set)
  • randomSubset(Set,ZZ)
  • randomSubset(VisibleList)
  • randomSubset(VisibleList,ZZ)
  • randomSubset(ZZ)
  • randomSubset(ZZ,ZZ)

For the programmer

The object randomSubset is a method function.


The source of this document is in /build/reproducible-path/macaulay2-1.25.06+ds/M2/Macaulay2/packages/Macaulay2Doc/functions/randomSubset-doc.m2:41:0.