File: README.md

package info (click to toggle)
rust-coreutils 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 505,620 kB
  • sloc: ansic: 103,594; asm: 28,570; sh: 8,910; python: 5,581; makefile: 472; cpp: 97; javascript: 72
file content (24 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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 

```rust
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.