Struct GameRng
pub struct GameRng(/* private fields */);Implementations§
§impl GameRng
impl GameRng
pub fn new(rng: StdRng) -> GameRng
pub fn from_entropy() -> GameRng
pub fn from_values(values: Vec<f64>) -> GameRng
pub fn from_values(values: Vec<f64>) -> GameRng
A deterministic source replaying values (cycling). Used by the test
harness so fight scripts get reproducible randomness through the native
fight_context.
pub fn from_entropy_recording() -> GameRng
pub fn from_entropy_recording() -> GameRng
An entropy source that records every f64 it draws. Draw against this
first, then call GameRng::recorded and feed the result into
GameRng::from_values to replay the same sequence. Returns the
default (empty) recording until used.
pub fn recorded(&self) -> Vec<f64>
pub fn recorded(&self) -> Vec<f64>
The sequence of f64 draws made so far. Empty for non-Recording
backends. Cloned out so the caller can build a Self::from_values
replay source from it.
pub fn random_bytes(&self) -> [u8; 16]
pub fn random_f64(&self) -> f64
pub fn random_index(&self, len: usize) -> usize
pub fn random_index(&self, len: usize) -> usize
Uniformly pick an index in [0, len), consuming exactly one f64
helper performed.
Prefer this over randint for picking a random element of
a collection. On the production Std backend randint draws via
StdRng::random_range (integer rejection sampling), which consumes a
different and variable amount of the RNG stream than a single f64 —
so it both picks a different element than floor(random() * len) would
for a given seed and desyncs every subsequent draw in the same handler.
The Fixed/Recording test backends map randint from a single f64,
so that divergence is invisible to tests. random_index is one f64 on
every backend, keeping selection identical across production and tests.
pub fn randint(&self, a: i64, b: i64) -> i64
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GameRng
impl RefUnwindSafe for GameRng
impl Send for GameRng
impl Sync for GameRng
impl Unpin for GameRng
impl UnwindSafe for GameRng
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].