| 1 | # Random constants |
| 2 | This crate provides compile time random number generation. |
| 3 | This allows you to insert random constants into your code that will be auto-generated at compile time. |
| 4 | |
| 5 | A new value will be generated every time the file is rebuilt. |
| 6 | This obviously makes the resulting binary or lib non-deterministic. (See below) |
| 7 | |
| 8 | # Example |
| 9 | |
| 10 | ```rust |
| 11 | use const_random::const_random ; |
| 12 | const MY_RANDOM_NUMBER: u32 = const_random!(u32); |
| 13 | ``` |
| 14 | This works exactly as through you have called: `OsRng.gen::<u32>()` at compile time. |
| 15 | So for details of the random number generation, see the `rand` crates documentation. |
| 16 | |
| 17 | The following types are supported: u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, isize and [u8; N]. |
| 18 | |
| 19 | # Deterministic builds |
| 20 | |
| 21 | Sometimes it is an advantage for build systems to be deterministic. To support this `const-random` reads the environmental |
| 22 | variable `CONST_RANDOM_SEED`. If this variable is set, it will be used as the seed for the random number generation. |
| 23 | Setting the same seed on a build of the same code should result in identical output. |
| 24 |