The generator that this module uses internally. It can be re-seeded with the seed function.
Generates a random boolean.
Return a boolean based on a probability.
A number between 0 and 1 representing the likelihood that true will be returned. A probability of 0 will always return false and a probability of 1 will always return true.
Selects a random element from array
.
Generates a random float between min
(inclusive) and max
(exlusive).
Generates a random integer between min
(inclusive) and max
(exlusive).
Selects a random element from items
.
Generates the next random number. Comparable to Math.random
.
A number between 0-1
Sets the seed for the internal random number generator.
Shuffles an array in place.
If you want to return a new array, use shuffled
.
Creates a shuffled copy of an array.
If you want to shuffle the array in place, use shuffle
.
Select a value from a list of weighted items. A higher weight means an item is more likely to be selected.
let item = RNG.weighted([
{ weight: 1, value: "foo" },
{ weight: 2, value: "bar" },
{ weight: 3, value: "baz" },
])
Generated using TypeDoc
Random Number Generator
import { RNG } from "silmarils"; // or import * as RNG from "silmarils/rng"; RNG.int(0, 10) // random int between 0 and 10 RNG.float(-1.0, 1.0) // random float between -1 and 1 RNG.boolean() // random boolean RNG.element([1, 2, 3]) // random element from array RNG.item(1, 2, 3) // random argument RNG.shuffle([1, 2, 3]) // shuffle in place RNG.shuffled([1, 2, 3]) // return a shuffled copy