routine roll

Documentation for routine roll assembled from the following types:

class Range

From Range

(Range) method roll

Performs the same function as Range.list.roll, but attempts to optimize by not actually generating the list if it is not necessary.

role Mixy

From Mixy

(Mixy) method roll

Similar to a Bag.roll, but with Real weights rather than integral ones.

role Baggy

From Baggy

(Baggy) method roll

Defined as:

Like an ordinary list roll, but returns keys of the invocant weighted by their values, as if the keys were replicated the number of times indicated by the corresponding value and then list roll used. The underlying metaphor for rolling is that you're throwing \$count dice that are independent of each other, which (in bag terms) is equivalent to picking a colored marble out your bag and then putting it back, and doing this \$count times. In dice terms, the number of marbles corresponds to the number of sides, and the number of marbles of the same color corresponds to the number of sides with the same color. (For "picking without replacement" see pick instead).

If * is passed to \$count, returns a lazy, infinite sequence of randomly chosen elements from the invocant.

role Setty

From Setty

(Setty) method roll

Returns a lazy list of \$count elements, each randomly selected from the set. Each random choice is made independently, like a separate die roll where each die face is a set element.

If * is passed as \$count, the list is infinite.

class Any

From Any

(Any) method roll

Defined as:

Coerces the invocant to a list by applying its .list method and uses List.roll on it.

\$m, in this case, is converted into a list and then a (weighted in this case) dice is rolled on it. See also List.roll for more information.

enum Bool

From Bool

(Bool) routine roll

Returns True or False if called without any argument. Otherwise returns \$count elements chosen at random. Note that each random choice from the enum is made independently, like a separate coin toss where each side of the coin represents one of the two values of the enum. If * is passed as \$count an infinite Seq of Bools is returned.

role Enumeration

From Enumeration

(Enumeration) method roll

Defined as:

They work on the defined class selecting one or n elements without eliminating them.

class List

From List

(List) routine roll

Defined as:

If \$count is supplied: Returns a sequence of \$count elements, each randomly selected from the list. Each random choice is made independently, like a separate die roll where each die face is a list element. If * is passed as \$count returns a lazy, infinite sequence of randomly chosen elements from the original list.

If \$count is omitted: Returns a single random item from the list, or Nil if the list is empty

Examples: