#random #generate #data

generate-random

Generate random data

1 unstable release

0.1.0 Apr 21, 2022

#509 in #random

Download history 32/week @ 2024-07-22 62/week @ 2024-07-29 24/week @ 2024-08-05 12/week @ 2024-08-12 19/week @ 2024-08-19 15/week @ 2024-08-26 10/week @ 2024-09-02 25/week @ 2024-09-09 22/week @ 2024-09-16 38/week @ 2024-09-23 40/week @ 2024-09-30 55/week @ 2024-10-07 33/week @ 2024-10-14 32/week @ 2024-10-21 32/week @ 2024-10-28 46/week @ 2024-11-04

147 downloads per month

MIT/Apache

6KB
94 lines

Generate-Random

Generate random data.

Example

use generate_random::GenerateRandom;

#[derive(GenerateRandom)]
enum MyEnum {
    A,
    C(bool),
    B {
        x: u8,
    },
    // Providing a weight allows changing the probabilities.
    // This variant is now twice as likely to be generated as the others.
    #[weight(2)]
    D,
}

let mut rng = rand::thread_rng();
let my_value = MyEnum::generate_random(&mut rng);

Documentation

Documentation


lib.rs:

Generate random data.

Examples

use generate_random::GenerateRandom;

#[derive(GenerateRandom)]
enum MyEnum {
    A,
    C(bool),
    B {
        x: u8,
    },
    // Providing a weight allows changing the probabilities.
    // This variant is now twice as likely to be generated as the others.
    #[weight(2)]
    D,
}

let mut rng = rand::thread_rng();
let my_value = MyEnum::generate_random(&mut rng);

Dependencies

~2MB
~43K SLoC