Crates.io | get-random-const |
lib.rs | get-random-const |
version | 2.0.3 |
source | src |
created_at | 2020-04-25 09:00:16.585183 |
updated_at | 2023-04-22 10:45:44.143498 |
description | Simple compile-time random generator |
homepage | |
repository | https://github.com/DoumanAsh/get-random-const |
max_upload_size | |
id | 233889 |
size | 6,744 |
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);