RandomTools Flavor: float - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

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

RandomTools Flavor: float

describe a flavor of a random floating-point number

 Calling Sequence float float(opts)

Parameters

 opts - equation(s) of the form option = value where option is one of range, digits, or method; specify options for the random floating-point number

Description

 • The flavor float describes a random floating-point number in a particular range.
 To describe a flavor of a random floating-point number, use either float or float(opts) (where opts is described following) as the argument to RandomTools[Generate] or as part of a structured flavor.
 • By default, the flavor float describes a random floating-point number logarithmically distributed in the range epsilon..1.0 - epsilon, inclusive, where epsilon = 10e-Digits.
 • You can modify the properties of the random floating-point number by using the float(opts) form of this flavor. The opts argument can contain one or more of the following equations.
 range = a..b
 This option specifies the range from which the random float is chosen. The range endpoints a and b are numeric and either a >= 0.0 or b <= 0.0.  All numerics are evaluated by using the setting of the digits option.
 If $a=0.$, then $a$ is set to the smallest value of the form $\mathrm{1eN}$ such that $b+\mathrm{1eN}>b$. If $b=0.$, then $b$ is set to the smallest value of the form $-\mathrm{1eN}$ such that $a-\mathrm{1eN}.
 If $b, an exception is raised.
 digits = posint
 This option specifies a positive integer to use as the Digits setting. The default setting is the current setting of the Digits environment variable.
 method = uniform or logarithmic
 This option specifies whether the floating-point number should be chosen logarithmically or uniformly from the interval.
 The logarithmic method is identical to listing all of the unique floating-point numbers that are found between the endpoints, and then choosing one of these randomly.
 The uniform method is similar to sampling from a uniform distribution that is bounded by the endpoints, and then converting this result into a floating-point number.
 The default value for this option is logarithmic.

Examples

 > $\mathrm{with}\left(\mathrm{RandomTools}\right):$
 > $\mathrm{Generate}\left(\mathrm{float}\right)$
 ${0.001715876735}$ (1)
 > $\mathrm{Generate}\left(\mathrm{float}\left(\mathrm{range}=2.532..7.723,\mathrm{digits}=4\right)\right)$
 ${2.537}$ (2)
 > $\left[\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{float}\right),i=1..10\right)\right]$
 $\left[{8.010929594}{}{{10}}^{{-10}}{,}{0.00003663573095}{,}{5.670977221}{}{{10}}^{{-8}}{,}{0.01831937262}{,}{4.324033882}{}{{10}}^{{-8}}{,}{0.06183108282}{,}{0.08394083871}{,}{0.0004646025782}{,}{7.467275627}{}{{10}}^{{-7}}{,}{0.0006955563440}\right]$ (3)
 > $\mathrm{sort}\left(\left[\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{float}\left(\mathrm{range}=0.0321..162.0,\mathrm{digits}=3\right)\right),i=1..10\right)\right]\right)$
 $\left[{0.0771}{,}{0.317}{,}{0.483}{,}{1.49}{,}{2.01}{,}{9.62}{,}{12.4}{,}{25.3}{,}{77.1}{,}{88.1}\right]$ (4)
 > $\mathrm{sort}\left(\left[\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{float}\left(\mathrm{range}=0.0321..162.0,\mathrm{digits}=3,\mathrm{method}=\mathrm{uniform}\right)\right),i=1..10\right)\right]\right)$
 $\left[{15.9}{,}{29.0}{,}{40.6}{,}{58.9}{,}{62.0}{,}{64.2}{,}{66.7}{,}{87.8}{,}{91.4}{,}{124.}\right]$ (5)
 > $\mathrm{Matrix}\left(3,3,\mathrm{Generate}\left(\mathrm{float}\left(\mathrm{range}=2..7\right)\mathrm{identical}\left(x\right)+\mathrm{float}\left(\mathrm{range}=2..7\right),\mathrm{makeproc}=\mathrm{true}\right)\right)$
 $\left[\begin{array}{ccc}{2.198304612}{}{x}{+}{2.417177801}& {4.984266209}{}{x}{+}{6.081172609}& {2.147944788}{}{x}{+}{3.884392678}\\ {5.287869586}{}{x}{+}{3.913778154}& {5.046698742}{}{x}{+}{3.185518681}& {2.698412071}{}{x}{+}{2.511091141}\\ {6.122068897}{}{x}{+}{3.461945556}& {4.513705832}{}{x}{+}{5.226667454}& {4.350272820}{}{x}{+}{2.595387438}\end{array}\right]$ (6)
 > $\mathrm{plots}[\mathrm{listplot}]\left(\mathrm{sort}\left(\left[\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{float}\left(\mathrm{range}=0.0321..162.0,\mathrm{digits}=3\right)\right),i=1..20\right)\right]\right)\right)$
 > $\mathrm{plots}[\mathrm{listplot}]\left(\mathrm{sort}\left(\left[\mathrm{seq}\left(\mathrm{Generate}\left(\mathrm{float}\left(\mathrm{range}=0.0321..162.0,\mathrm{digits}=3,\mathrm{method}=\mathrm{uniform}\right)\right),i=1..20\right)\right]\right)\right)$

 See Also

## Was this information helpful?

 Please add your Comment (Optional) E-mail Address (Optional) What is ? This question helps us to combat spam