Skip to main content

SplitMix64

Struct SplitMix64 

Source
pub struct SplitMix64 { /* private fields */ }
Expand description

Tiny deterministic PRNG. State is one u64; output passes the obvious goodness tests (BigCrush-ish) and is more than enough for upgrade-tree procgen. Not for cryptography.

Implementations§

Source§

impl SplitMix64

Source

pub fn new(seed: u64) -> Self

Source

pub fn from_coords(seed: u64, x: i32, y: i32, salt: u64) -> Self

Combine a base seed with three coordinate-like ints into a fresh PRNG state. salt lets adjacent call sites avoid stepping on each other (e.g. “noise lookup” vs “edge roll” at the same lot).

Source

pub fn next_u64(&mut self) -> u64

Source

pub fn next_f64(&mut self) -> f64

Returns a value in [0.0, 1.0). 53-bit mantissa for double precision.

Source

pub fn range_f64(&mut self, lo: f64, hi: f64) -> f64

Returns a value in [lo, hi).

Source

pub fn range_usize(&mut self, max: usize) -> usize

Returns an integer in [0, max). Trivial modulo bias is acceptable for procgen — the bias for max < 1e9 is well below any other source of variance in the system.

Source

pub fn bool_with_prob(&mut self, p: f64) -> bool

True with probability p.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.