[−][src]Crate randomize
Simple and minimalist randomization.
NOT FOR CRYPTOGRAPHIC PURPOSES.
Basic Usage
- Pick a generator, PCG32 or PCG64, depending on the output type you want.
- Seed your generator from wherever. However you wanna do it that your
platform supports. The generators have a
state
andinc
value. Thestate
will change with each call, theinc
is like a stream selection value that doesn't change when you use the generator. If you don't care about stream selection just pass your seed value to both arguments and it'll all "just work". - Call next_u32 or next_u64 to get your numbers.
- You can use RandRangeU32 for bounded integer randomization.
That's it, that's the whole lib. No generics, no traits, no breaking changes issued as patch releases, none of that.
Floating Point
Unfortunately, there's many possible float distributions a person might want, so you'll have to call one of the float conversion functions yourself. I've included conversions for the five most commonly used floating point ranges.
Range | 32-bit | 64-bit |
---|---|---|
[0.0, 1.0) | f32_half_open_right | f64_half_open_right |
(0.0, 1.0] | f32_half_open_left | f64_half_open_left |
(0.0, 1.0) | f32_open | f64_open |
[0.0, 1.0] | f32_closed | f64_closed |
[-1.0, 1.0] | f32_closed_neg_pos | f64_closed_neg_pos |
Re-exports
pub use formulas::*; |
Modules
formulas | Various generator and conversion formulas. This module is a "junk drawer" of stuff. |
Macros
branchless_max | Fiddly to use, but totally gets you the maximum without branching. |
branchless_min | Fiddly to use, but totally gets you the minimum without branching. |
Structs
PCG32 | A permuted congruential generator with 32-bit output. Pick this by default. |
PCG64 | A permuted congruential
generator
with 64-bit output. Pick this if you want to do stuff with |
RandRangeU32 | An inclusive random range with a |
Functions
rdtsc_u64 | Calls |