 RandomTools - Maple Programming Help

Home : Support : Online Help : Programming : Random Objects : RandomTools package : Commands : RandomTools/AddFlavor

RandomTools

 add a flavor template to generate random objects

Parameters

 flvr - equation of the form $x=\mathrm{flavor}$ where x is any symbol and flavor is a procedure or module; defines the name of the flavor to add

Description

 • The AddFlavor(flvr) function teaches the Generate function about a new flavor.  The flavor can be a procedure or a module definition, and it determines the form of the returned random object.
 • If flavor is a procedure, RandomTools[Generate](flvr) calls that procedure.
 If flavor is a module, it must have an export named Main that is of type procedure. In this case, RandomTools[Generate](flvr) calls ${\mathrm{flavor}}_{'\mathrm{Main}'}$.
 Note:  The call x[op1, op2](arg1, arg2) translates into the function call flavor['Main'][op1, op2](arg1, arg2).
 • This function is part of the RandomTools package, and so it can be used in the form AddFlavor(..) only after executing the command with(RandomTools). However, it can always be accessed through the long form of the command by using the form RandomTools[AddFlavor](..).

Examples

 > $\mathrm{with}\left(\mathrm{RandomTools}\right):$
 > $\mathrm{Generate}\left(A\right)$
 > $\mathrm{AddFlavor}\left(A=\mathrm{rand}\left(1..20\right)\right):$
 > $\mathrm{Generate}\left(A\right)$
 ${15}$ (1)
 > $\mathrm{Generate}\left(A\right)$
 ${13}$ (2)
 > $\mathrm{member}\left(A,\left[\mathrm{GetFlavors}\left(\right)\right]\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{Generate}\left(\mathrm{alphachar}\right)$
 > AddFlavor(alphachar = proc() [a,b,c,d,e,f][rand(1..6)()] end proc):
 > $\mathrm{member}\left(\mathrm{alphachar},\left[\mathrm{GetFlavors}\left(\right)\right]\right)$
 ${\mathrm{true}}$ (4)