Sign in

    sayoi7799/moon_rough/random does not have a README file

    Random

    pub struct Random {
    // private fields
    }

    rough.js' Random: a Park-Miller (MINSTD, multiplier 48271) generator.

    Random::new

    fn Random::new(seed : Int, source? : RandomSource) -> Random

    new Random(seed). With seed 0, next delegates to source.fallback().

    Random::next

    fn Random::next(self : Random) -> Double

    The next number in [0, 1).

    rough.js: ((2 ** 31 - 1) & (this.seed = Math.imul(48271, this.seed))) / 2 ** 31. MoonBit's Int multiplication wraps around at 32 bits exactly like Math.imul.

    RandomSource

    pub struct RandomSource {
    // private fields
    }

    Where the random numbers that rough.js takes from Math.random() come from. rough.js uses Math.random() when the seed is 0, for the dot positions of the dots fill style and as a fallback in the hachure filler, so those outputs are not reproducible in rough.js itself; here the source can be injected to make them deterministic.

    A source is shared by all Randoms created from the same generator and counts the numbers drawn, which the tests compare with rough.js.

    RandomSource::default

    fn RandomSource::default() -> RandomSource

    The default source: Math.random() is replaced by a Park-Miller sequence with a fixed seed (DEFAULT_FALLBACK_SEED). Unlike JavaScript's Math.random() it starts at the same point in every run; pass RandomSource::new(f) with your own generator for varying output.

    RandomSource::fallback

    fn RandomSource::fallback(self : RandomSource) -> Double

    The equivalent of calling Math.random().

    RandomSource::fallback_calls

    fn RandomSource::fallback_calls(self : RandomSource) -> Int

    How many Math.random() replacements were drawn.

    RandomSource::new

    fn RandomSource::new(fallback : () -> Double) -> RandomSource

    A source whose Math.random() replacement is fallback, which must return numbers in [0, 1).

    RandomSource::park_miller

    fn RandomSource::park_miller(seed : Int) -> RandomSource

    A source whose Math.random() replacement is the same Park-Miller sequence rough.js' Random produces for seed (which must not be 0).

    RandomSource::seeded_calls

    fn RandomSource::seeded_calls(self : RandomSource) -> Int

    How many seeded numbers (Random::next with a non-zero seed) were drawn.

    DEFAULT_FALLBACK_SEED

    let DEFAULT_FALLBACK_SEED : Int

    The seed of RandomSource::default().

    new_seed

    fn new_seed(source : RandomSource) -> Int

    randomSeed() / rough.newSeed(): Math.floor(Math.random() * 2 ** 31).

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io