cr
const-random
cargo install const-random
cr

const-random

Macro to generate random constants in Rust https://xkcd.com/221/

by Tom Kaitchuck

0.1.13 (see all)License:MIT OR Apache-2.0
cargo install const-random
Readme

Random constants

This crate provides compile time random number generation. This allows you to insert random constants into your code that will be auto-generated at compile time.

A new value will be generated every time the file is rebuilt. This obviously makes the resulting binary or lib non-deterministic. (See below)

Example

use const_random::const_random  ;
const MY_RANDOM_NUMBER: u32 = const_random!(u32);

This works exactly as through you have called: OsRng.gen::<u32>() at compile time. So for details of the random number generation, see the rand crates documentation.

The following types are supported: u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, and isize.

Deterministic builds

Sometimes it is an advantage for build systems to be deterministic. To support this const-random reads the environmental variable CONST_RANDOM_SEED. If this variable is set, it will be used as the seed for the random number generation. Setting the same seed on a build of the same code should result in identical output.

GitHub Stars

42

LAST COMMIT

2yrs ago

MAINTAINERS

1

CONTRIBUTORS

7

OPEN ISSUES

1

OPEN PRs

2
VersionTagPublished
0.1.13
2yrs ago
0.1.12
2yrs ago
0.1.11
2yrs ago
0.1.10
2yrs ago
No alternatives found
No tutorials found
Add a tutorial