Crate randomize[−][src]
A dead simple to use randomization library for rust.
The library contains a trait for an RNG family, PCG
, and two main
implementations from that family: PCG32
and PCG64
.
use randomize::{u64_from_time, PCG, PCG32}; let time64 = u64_from_time(); let gen = &mut PCG32::new(time64, time64); println!("here's a u32 value: {}", gen.next_u32());
There are also a selection of functions that will automatically use a
global, lazily initialized, mutex guarded PCG32
value to get you your
results.
use randomize; if randomize::any() { let x: u32 = randomize::any(); println!("x is a u32: {}", x); } else { let x: [char; 10] = randomize::any(); println!("x is a 10 character array: {:?}", x); let i = randomize::any_in_range(0 .. x.len()).unwrap(); println!("The character at index {} was {}", i, x[i]); }
This library gives priority to ease of use rather than trying to cover all
possible uses. If you want a totally comprehensive randomization library for
all possible cases then you probably want the rand
crate.
NOT FOR CRYPTOGRAPHIC PURPOSES.
Macros
make_compact_pcg32_type |
Makes a variant of the |
make_compact_pcg64_type |
Makes a variant of the |
Structs
AsciiCharacter |
A |
F32ZeroToOneExclusive |
A |
F32ZeroToOneInclusive |
A |
PCG32 |
A permuted congruential generator with 32-bit output and per-generator stream selection. |
PCG64 |
A permuted congruential generator with 64-bit output and per-generator stream selection. |
PercentChance |
A |
RandRangeInclusive32 |
An inclusive random range with |
RandRangeInclusiveUsize |
An inclusive random range with |
Constants
d4 |
A const for 1d4. |
d6 |
A const for 1d6. |
d8 |
A const for 1d8. |
d10 |
A const for 1d10. |
d12 |
A const for 1d12. |
d20 |
A const for 1d20. |
reciprocal_u32_max_float |
A single step of the |
reciprocal_u64_max_double |
A single step of the |
Traits
AnyRandom |
A trait for types can can be generated in "any" state. |
Distribution |
A trait for types that represent some sort of special distribution other
than what the |
PCG |
The trait for any type that's a form of permuted congruential generator. |
Functions
any |
Calls |
any_ascii |
Samples the |
any_f32_zero_to_one_exclusive |
Samples the |
any_f32_zero_to_one_inclusive |
Samples the |
any_in_range |
Constructs and uses a
|
get_global_generator |
Obtains a
|
percent_chance |
Samples the given |
u64_from_time |
Returns a |