RandomTools Flavor: set
describe a set of random objects
Calling Sequence
Parameters
Description
Examples
Compatibility
set(flav, n)
set(flav, n, opt)
flav
-
random flavor
n
non-negative integer
opt
(optional) one or more keyword options of the form keyword = value, where the keyword is either exact or limit
The flavor set describes a set containing n entries where the entries of this set are described by the given random flavor flav.
By default, the final set can contain fewer than n entries if the same object is generated more than once. If the exact = true option is given, either as the keyword or as the equation exact = true, then a set of exactly n values is returned. For this to succeed, the number of possible values generated by the given flavor has to be at least n. This can be detected reliably for some flavors such as integer or choose, but not for all flavors. The option exact = true can also be specified as just exact; the default can be specified explicitly as exact = false.
If Maple cannot detect whether the flavor supports at least n values and the exact option is set to true, then it will try to generate sufficiently many values. However, this may fail. In this situation, if Maple runs a certain limit number of iterations, it will error out. By default, this limit is 100 iterations; it can be set to any positive number using the limit option, or to infinity to disable the limit. If the exact option is not set to true, the limit option is ignored.
This flavor can be used as an argument to RandomTools[Generate] or as part of a structured flavor.
with⁡RandomTools:
The following sets have fewer than 10 entries, because some entries were generated twice.
Generate⁡set⁡posint⁡range=10,10
1,2,4,5,6,7,8,10
Generate⁡set⁡rational⁡denominator=6,10
−23,−12,−13,12,13,23,56
This is corrected with the exact option.
Generate⁡set⁡rational⁡denominator=6,10,exact
0,−56,−23,−12,−16,12,13,16,23,56
The following will fail, because there are only 11 values that can be generated.
Generate⁡set⁡rational⁡denominator=6,100,exact
Error, (in RandomTools:-Generate) requested exactly 100 different random entries, but unsuccessful after 100 iterations (11 were found)
The following should eventually succeed, because there are 15625 possible lists of the given flavor. However, Maple does not have specialized code to detect this case. Trying to generate almost all possible entries by random chance is likely to take a large number of iterations, so it will most probably fail in this case.
Generate⁡set⁡list⁡integer⁡range=1..5,6,15600,exact
Error, (in RandomTools:-Generate) requested exactly 15600 different random entries, but unsuccessful after 100 iterations (15533 were found)
If we set the limiting number of iterations sufficiently high, we do get the correct result.
result≔Generate⁡set⁡list⁡integer⁡range=1..5,6,15600,exact,limit=∞:
numelems⁡result
15600
The RandomTools Flavor: set command was updated in Maple 2019.
The exact and limit options were introduced in Maple 2019.
For more information on Maple 2019 changes, see Updates in Maple 2019.
See Also
flavor/structured
rand
RandomTools
RandomTools[Generate]
set
Download Help Document