RandomTools Flavor: choose - Maple Programming Help

Home : Support : Online Help : Programming : Random Objects : RandomTools package : Flavors : RandomTools/flavor/choose

RandomTools Flavor: choose

describe a flavor which chooses from a collection

 Calling Sequence choose(collection)

Parameters

 collection - set, list, Matrix, Vector, Array, or table

Description

 • The flavor choose selects one of the entries in a non-empty collection with equal probability.
 This flavor can be used as an argument to RandomTools[Generate] or as part of a structured flavor.
 • The flavor choose cannot select an element from a non-array table that has an indexing function.

Examples

 > $\mathrm{with}\left(\mathrm{RandomTools}\right):$
 > $\mathrm{Generate}\left(\mathrm{choose}\left(\left\{a,b,c,d,e,f\right\}\right)\right)$
 ${e}$ (1)
 > $\mathrm{Generate}\left(\mathrm{choose}\left(⟨A,B,C,\mathrm{D}⟩\right)\right)$
 ${C}$ (2)
 > $\mathrm{Generate}\left(\mathrm{choose}\left(\mathrm{Array}\left(10..12,15..17,13..15,\left(i,j,k\right)↦\left[i,j,k\right]\right)\right)\right)$
 $\left[{12}{,}{16}{,}{13}\right]$ (3)
 > $\mathrm{Generate}\left(\mathrm{choose}\left(\mathrm{table}\left(\left[a=b,c=d\right]\right)\right)\right)$
 ${b}$ (4)
 > $\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{choose}\left(⟨⟨1,2⟩|⟨3,4⟩⟩\right)\right),i=1..10\right)$
 ${4}{,}{3}{,}{4}{,}{1}{,}{2}{,}{2}{,}{2}{,}{4}{,}{4}{,}{1}$ (5)
 > $\mathrm{Matrix}\left(3,3,\mathrm{Generate}\left(\mathrm{choose}\left(\left\{0,1\right\}\right),\mathrm{makeproc}=\mathrm{true}\right)\right)$
 $\left[\begin{array}{ccc}{0}& {1}& {0}\\ {1}& {0}& {1}\\ {1}& {0}& {0}\end{array}\right]$ (6)