1 unstable release

0.1.0 Apr 21, 2022

#2968 in Rust patterns

Download history 7/week @ 2024-02-18 13/week @ 2024-02-25 8/week @ 2024-03-03 10/week @ 2024-03-10 8/week @ 2024-03-17 38/week @ 2024-03-31 2/week @ 2024-04-07 18/week @ 2024-04-14

59 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

~1.5MB
~38K SLoC