get-random-const

Crates.ioget-random-const
lib.rsget-random-const
version2.0.3
sourcesrc
created_at2020-04-25 09:00:16.585183
updated_at2023-04-22 10:45:44.143498
descriptionSimple compile-time random generator
homepage
repositoryhttps://github.com/DoumanAsh/get-random-const
max_upload_size
id233889
size6,744
Douman (DoumanAsh)

documentation

https://docs.rs/get-random-const/

README

get-random-const

Crates.io Documentation

Macro to generate random at compile time

use get_random_const::random;

const RANDOM_U8: u8 = random!(u8);
assert_ne!(RANDOM_U8, 0);

static RANDOM_I32: i32 = random!(i32);
assert_ne!(RANDOM_I32, 0);

let random_u32 = random!(u32);
assert_ne!(random_u32, 0);

let random_array = random!([u32;5]);
assert_eq!(random_array.len(), 5);

for elem in random_array.iter() {
    assert_ne!(*elem, 0);
}

let random_array: [u32; 0] = random!([u32;0]); //Well, I guess you can if you want?
assert_eq!(random_array.len(), 0);
Commit count: 7

cargo fmt