All Projects → tkaitchuck → constrandom

tkaitchuck / constrandom

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
Macro to generate random constants in Rust https://xkcd.com/221/

Programming Languages

rust
11053 projects

Labels

Projects that are alternatives of or similar to constrandom

abaK
ABAP constants done right
Stars: ✭ 26 (-46.94%)
Mutual labels:  constants
php-helpers
An extensive set of PHP helper functions and classes.
Stars: ✭ 27 (-44.9%)
Mutual labels:  constants
Giotto
Theme manager for your app: apply styles to anything you want through a plist file
Stars: ✭ 18 (-63.27%)
Mutual labels:  constants
http-constants
The missing PHP constants for HTTP header fields
Stars: ✭ 19 (-61.22%)
Mutual labels:  constants
ConfuserEx-Mod-By-Bed
Beds Protector | Best free obfuscation out right now
Stars: ✭ 297 (+506.12%)
Mutual labels:  constants
node-v
🔒 Secure ❄️ Synchronized ⚡️ Realtime ☁️ Cloud 🌈 Native JavaScript Variables & Events
Stars: ✭ 27 (-44.9%)
Mutual labels:  constants
elm-constants
Generate constant values in Elm from your environment
Stars: ✭ 42 (-14.29%)
Mutual labels:  constants
ImHex-Patterns
Hex patterns, include patterns and magic files for the use with the ImHex Hex Editor
Stars: ✭ 192 (+291.84%)
Mutual labels:  constants

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, isize and [u8; N].

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].