Sign in

    moonbit-community/dummy/core does not have a README file

    DummyDefault

    pub(open) trait DummyDefault {
    fn dummy_default(
    Rand
    ) -> Self raise DummyError
    }

    Trait for project-specific default fake values.

    Implement this when a type should have a natural default generator, then call Type::dummy_default(rng) directly or compose it inside a Gen.
    impl DummyDefault for Int
    impl DummyDefault for Option[T]
    impl DummyDefault for Result[T, E]
    impl DummyDefault for Array[T]
    impl DummyDefault for Tuple2[A, B]
    impl DummyDefault for Tuple3[A, B, C]
    impl DummyDefault for Tuple4[A, B, C, D]

    DummyError

    pub(all) suberror DummyError {
    InvalidRange(String)
    InvalidCount(Int)
    EmptyCandidates(String)
    UnsupportedLocale(String)
    } derive(Eq,
    Debug
    )

    Checked errors raised by generator construction or sampling.

    Most facade calls return Gen[T]; these errors are usually observed when calling dummy or sample with invalid ranges, empty candidate lists, or a locale that has no meaningful data for a locale-specific category.

    CountRange

    pub(all) struct CountRange {
    min : Int
    max : Int
    } derive(Eq,
    Debug
    )

    Inclusive count range for lengths and collection sizes.

    Counts must be non-negative. Both min and max are possible outputs.

    CountRange::sample

    fn CountRange::sample(self : CountRange, rng :
    Rand
    ) -> Int raise DummyError

    Sample a count from [min, max].

    CountRange::validate

    fn CountRange::validate(self : CountRange) -> Unit raise DummyError

    Validate that the count range is non-negative and ordered.

    Gen

    pub(all) struct Gen[T] {
    run : (
    Rand
    ) -> T raise DummyError
    }

    Lazy dummy-data generator.

    A Gen[T] stores generation logic and only consumes randomness when dummy or sample is called.

    Gen::dummy

    fn[T] Gen::dummy(self : Gen[T], rng :
    Rand
    ) -> T raise DummyError

    Produce one value from the generator.

    The supplied RNG is advanced in place, so repeated calls form a deterministic sequence for a fixed seed.

    Gen::flat_map

    fn[T, U] Gen::flat_map(self : Gen[T], f : (T) -> Gen[U]) -> Gen[U]

    Build a dependent generator from each produced value.

    The outer and inner generators share the same RNG so composition remains a single reproducible sequence.

    Gen::map

    fn[T, U] Gen::map(self : Gen[T], f : (T) -> U) -> Gen[U]

    Transform generated values without changing when randomness is consumed.

    Gen::new

    fn[T] Gen::new(run : (
    Rand
    ) -> T raise DummyError) -> Gen[T]

    Create a generator from a function that consumes a shared RNG.

    Gen::pure

    fn[T] Gen::pure(value : T) -> Gen[T]

    Create a generator that always yields value without consuming randomness.

    Gen::sample

    fn[T] Gen::sample(self : Gen[T], count~ : Int, rng :
    Rand
    ) -> Array[T] raise DummyError

    Produce count values by repeatedly running the same generator.

    Raises DummyError::InvalidCount when count is negative.

    IntRange

    pub(all) struct IntRange {
    start : Int
    end : Int
    } derive(Eq,
    Debug
    )

    Half-open integer range used by integer fakers.

    start is possible and end is excluded, matching MoonBit/random limit semantics. The range is validated when sampled.

    IntRange::sample

    fn IntRange::sample(self : IntRange, rng :
    Rand
    ) -> Int raise DummyError

    Sample an integer from [start, end).

    IntRange::validate

    fn IntRange::validate(self : IntRange) -> Unit raise DummyError

    Validate that end is greater than start.

    count_range

    fn count_range(min : Int, max : Int) -> CountRange

    Construct an inclusive count range [min, max].

    default_seeded

    fn default_seeded() ->
    Rand

    Create the package default deterministic RNG.

    hex_byte

    fn hex_byte(value : Int) -> String

    Render an integer as a two-character uppercase hexadecimal byte.

    hex_u16

    fn hex_u16(value : Int) -> String

    Render an integer as a four-character uppercase hexadecimal word.

    int_range

    fn int_range(start : Int, end : Int) -> IntRange

    Construct a half-open integer range [start, end).

    join_strings

    fn join_strings(items : ArrayView[String], sep : String) -> String

    Join strings with sep.

    This small wrapper keeps call sites independent from concrete array/view conversions.

    normalize_seed

    fn normalize_seed(seed_bytes : Bytes) -> Bytes

    Normalize arbitrary seed bytes to the 32-byte ChaCha8 seed shape.

    Bytes beyond 32 are ignored; missing bytes are filled with zero. This makes short human-readable seeds convenient while keeping output deterministic.

    numerify

    fn numerify(pattern : String, rng :
    Rand
    ) -> String

    Apply number formatting rules.

    # becomes a digit from 0 through 9, ^ becomes a digit from 1 through 9, and every other character is copied unchanged.

    one_of

    fn[T] one_of(items : ArrayView[Gen[T]]) -> Gen[T] raise DummyError

    Choose one generator uniformly from items.

    Raises DummyError::EmptyCandidates if no candidates are supplied.

    pad_left

    fn pad_left(value : String, width : Int, pad : Char) -> String

    Left-pad value with pad until it reaches width code units.

    pick

    fn[T] pick(items : ArrayView[T], rng :
    Rand
    ) -> T raise DummyError

    Pick one item uniformly from a non-empty array view.

    pick_string

    fn pick_string(items : ArrayView[String], rng :
    Rand
    ) -> String raise DummyError

    Pick one string uniformly from a non-empty array view.

    random_ascii

    fn random_ascii(len : Int, rng :
    Rand
    ) -> String raise DummyError

    Generate a lowercase ASCII string of length len.

    random_bool

    fn random_bool(ratio : Int, rng :
    Rand
    ) -> Bool raise DummyError

    Sample a boolean that is true with ratio percent probability.

    ratio must be in 0..=100.

    random_digit_string

    fn random_digit_string(len : Int, rng :
    Rand
    ) -> String raise DummyError

    Generate a decimal digit string of length len.

    random_int

    fn random_int(range : IntRange, rng :
    Rand
    ) -> Int raise DummyError

    Sample an integer from a validated IntRange.

    render_template

    fn render_template(template : String, pairs : ArrayView[(String, String)]) -> String

    Render a template by replacing token strings with values.

    Tokens are literal strings such as {FirstName}. Replacement is sequential, so callers should avoid overlapping token names.

    repeat_pick

    fn repeat_pick(items : ArrayView[String], count : Int, rng :
    Rand
    ) -> Array[String] raise DummyError

    Pick count strings from items, preserving sample order.

    seed

    fn seed(seed_bytes : Bytes) ->
    Rand

    Create a deterministic ChaCha8 RNG from arbitrary seed bytes.

    weighted

    fn[T] weighted(items : ArrayView[(Int, Gen[T])]) -> Gen[T] raise DummyError

    Choose one generator according to positive integer weights.

    Weights less than or equal to zero are ignored. Raises if the list is empty or if no candidate has a positive weight.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io