The rand routine

Combined from primary sources listed below.

In role Real ( Type/Real )§

See primary docmentation in context for routine rand.

routine rand§

sub term:<rand> (--> Num:D)
method rand(Real:D: --> Real:D)

Returns a pseudo-random number between zero (inclusive) and the number (non-inclusive). The Bridge method is used to coerce the Real to a numeric that supports rand method.

The term form returns a pseudo-random Num between 0e0 (inclusive) and 1e0 (non-inclusive.)

In class Cool ( Type/Cool )§

See primary docmentation in context for method rand.

method rand§

method rand()

Coerces the invocant to Num and returns a pseudo-random value between zero and the number.

say 1e5.rand;           # OUTPUT: «33128.495184283␤»

In class Range ( Type/Range )§

See primary docmentation in context for method rand.

method rand§

method rand(Range:D --> Num:D)

Returns a pseudo-random value belonging to the range.

say (1^..5).rand;                              # OUTPUT: «1.02405550417031␤»
say (0.1..0.3).rand;                           # OUTPUT: «0.2130353370062␤»

In class Num ( Type/Num )§

See primary docmentation in context for method rand.

method rand§

method rand(Num:D: --> Num)

Returns a pseudo random number between 0 and the invocant.

In Terms ( Language/terms )§

See primary docmentation in context for term rand.

term rand§

Returns a pseudo-random Num in the range 0..^1.