pub struct LegacyRandom {
seed: i64,
next_gaussian: f64,
}Expand description
Legacy Minecraft random number generator based on a Linear Congruential Generator (LCG).
This implementation mirrors Java’s java.util.Random which Minecraft originally used.
Fields§
§seed: i64§next_gaussian: f64Implementations§
Source§impl LegacyRandom
impl LegacyRandom
Sourcepub const fn from_seed(seed: u64) -> Self
pub const fn from_seed(seed: u64) -> Self
Creates a new LegacyRandom instance from the given seed.
The seed is XORed with the LCG multiplier and masked to 48 bits, matching Java’s behavior.
Sourcepub const fn set_seed(&mut self, seed: i64)
pub const fn set_seed(&mut self, seed: i64)
Re-seeds this generator, matching Java’s Random.setSeed.
Sourcepub fn set_large_feature_seed(&mut self, seed: i64, chunk_x: i32, chunk_z: i32)
pub fn set_large_feature_seed(&mut self, seed: i64, chunk_x: i32, chunk_z: i32)
Matches vanilla’s WorldgenRandom.setLargeFeatureSeed.
Sourcepub fn set_large_feature_with_salt(
&mut self,
seed: i64,
x: i32,
z: i32,
salt: i32,
)
pub fn set_large_feature_with_salt( &mut self, seed: i64, x: i32, z: i32, salt: i32, )
Matches vanilla’s WorldgenRandom.setLargeFeatureWithSalt.
const fn next(&mut self, bits: u64) -> i32
const fn next_random(&mut self) -> i64
Sourceconst fn skip(&mut self, count: u64)
const fn skip(&mut self, count: u64)
Advance the LCG by count steps in O(log count) time.
Equivalent to calling next_random() count times and discarding the
results. Each LCG step is the affine map T(s) = LCG_A · s + LCG_C (mod 2^48).
Composing two such maps (A₂, C₂) ∘ (A₁, C₁) yields (A₂·A₁, A₂·C₁ + C₂),
so binary exponentiation over the composition computes T^count in
O(log count) without ever evaluating individual steps.
const fn so the compiler can fold the entire skip when count is a
compile-time constant (as in EndIslands::new where it’s literally 17292).
Trait Implementations§
Source§impl From<LegacyRandom> for RandomSource
impl From<LegacyRandom> for RandomSource
Source§fn from(v: LegacyRandom) -> RandomSource
fn from(v: LegacyRandom) -> RandomSource
Source§impl MarsagliaPolarGaussian for LegacyRandom
impl MarsagliaPolarGaussian for LegacyRandom
Source§fn stored_next_gaussian(&self) -> Option<f64>
fn stored_next_gaussian(&self) -> Option<f64>
Source§fn set_stored_next_gaussian(&mut self, value: Option<f64>)
fn set_stored_next_gaussian(&mut self, value: Option<f64>)
Source§fn calculate_gaussian(&mut self) -> f64
fn calculate_gaussian(&mut self) -> f64
Source§impl Random for LegacyRandom
impl Random for LegacyRandom
fn fork(&mut self) -> Self
fn next_i32(&mut self) -> i32
fn next_i32_bounded(&mut self, bound: i32) -> i32
fn next_i64(&mut self) -> i64
fn next_f32(&mut self) -> f32
fn next_f64(&mut self) -> f64
fn next_bool(&mut self) -> bool
fn next_gaussian(&mut self) -> f64
fn next_positional(&mut self) -> RandomSplitter
fn consume_count(&mut self, count: i32)
fn next_i32_between(&mut self, min: i32, max: i32) -> i32
fn next_i32_between_exclusive(&mut self, min: i32, max: i32) -> i32
fn triangle(&mut self, min: f64, max: f64) -> f64
fn triangle_f32(&mut self, min: f32, max: f32) -> f32
Source§impl TryInto<LegacyRandom> for RandomSource
impl TryInto<LegacyRandom> for RandomSource
Auto Trait Implementations§
impl Freeze for LegacyRandom
impl RefUnwindSafe for LegacyRandom
impl Send for LegacyRandom
impl Sync for LegacyRandom
impl Unpin for LegacyRandom
impl UnsafeUnpin for LegacyRandom
impl UnwindSafe for LegacyRandom
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreArc<SyncMutex<>>