[−][src]Trait randomize::Gen32
For random number generators with a primary output of u32
per use.
All other methods then default in terms of the next_u32
method.
Required methods
Loading content...Provided methods
fn next_bool(&mut self) -> bool
Produce a bool
fn next_u8(&mut self) -> u8
Produce a u8
fn next_u16(&mut self) -> u16
Produce a u16
fn next_u64(&mut self) -> u64
Produce a u64
fn next_f32_unit(&mut self) -> f32
Returns an f32
in the unsigned unit range, [0, 1]
fn next_f32_signed_unit(&mut self) -> f32
Returns an f32
in the signed unit range, [-1, 1]
fn next_bounded(&mut self, b: u32) -> u32
Gives a value within 0 .. B
This is often more efficient than making a BoundedRandU32
if you don't
need to use a specific bound value more than once.
Panics
- If the input is 0.
fn dice(&mut self, count: i32, sides: i32) -> i32
Performs an XdY
style dice roll.
- If
count
orsides
are less than 0, the output is 0. - Requires linear time to compute based on
count
. Expected inputs are 20 or less.
fn step_ed4(&mut self, step: i32) -> i32
Performs a "step" roll according to the 4e chart.
This relates to a particular paper and pencil RPG. If you're not familiar with the game that's fine.
- The average output of any positive value is approximately equal to the input, with no hard upper bound.
- The output of any non-positive value is 1.
- Requires linear time to compute. Expected inputs are 30 or less.
fn sundown_pool(&mut self, size: u32) -> u32
Rolls an After Sundown style dice pool.
This relates to a particular paper and pencil RPG. If you're not familiar with the game that's fine.
size
D6s are rolled. This returns the number of them that are a 5 or
fn rn_bounded_luck(&mut self, x: i32, luck: i32) -> i32
Returns a value in 0..x
with the odds modified by luck
.
This pertains to a particular video game. If you're not familiar with the game that's fine.
- This is a constant time operation.
- higher luck pushes the output toward zero.
- lower luck pushes the output towards the upper value.
luck
is expected to be +/-30
Panics
- If
x
is 0 or less.
fn rn_exponential_decay(&mut self, x: i32) -> i32
Returns a value of 1 or more.
- The output starts at 1, then has a repeated
1/x
chance of getting +1. - As soon as the value doesn't get a +1, it is returned.
Panics
- If
x
is less than 2.
fn rn_z(&mut self, i: i32) -> i32
Returns a value.
This pertains to a particular video game. If you're not familiar with the game that's fine.
- The input value affects the output.
- This runs in constant time.
fn pick<T>(&mut self, buf: &[T]) -> T where
Self: Sized,
T: Copy,
Self: Sized,
T: Copy,
Gets a value out of the slice given (by copy).
- The default impl will not pick past index
u32::MAX
.
fn pick_ref<'b, T>(&mut self, buf: &'b [T]) -> &'b T where
Self: Sized,
Self: Sized,
Gets a value out of the slice given (by shared ref).
- The default impl will not pick past index
u32::MAX
.
fn pick_mut<'b, T>(&mut self, buf: &'b mut [T]) -> &'b mut T where
Self: Sized,
Self: Sized,
Gets a value out of the slice given (by unique ref).
- The default impl will not pick past index
u32::MAX
.
fn shuffle<T>(&mut self, buf: &mut [T]) where
Self: Sized,
Self: Sized,
Shuffles a slice in O(len)
time.
- The default impl shuffles only the first
u32::MAX
elements.