mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
type use of rng
This commit is contained in:
parent
32eb34f226
commit
c632eb4ea3
|
@ -54,8 +54,9 @@ impl Default for RandomNumberGenerator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLOBAL_RNG: AtomicU128 =
|
static GLOBAL_RNG: AtomicU128 = AtomicU128::new(unsafe {
|
||||||
AtomicU128::new(unsafe { core::mem::transmute(RandomNumberGenerator::new().state) });
|
core::mem::transmute::<[u32; 4], u128>(RandomNumberGenerator::new().state)
|
||||||
|
});
|
||||||
|
|
||||||
/// Using a global random number generator, provides the next random number
|
/// Using a global random number generator, provides the next random number
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
@ -64,7 +65,10 @@ pub fn gen() -> i32 {
|
||||||
let data_u32: [u32; 4] = unsafe { core::mem::transmute(data) };
|
let data_u32: [u32; 4] = unsafe { core::mem::transmute(data) };
|
||||||
let mut rng = RandomNumberGenerator { state: data_u32 };
|
let mut rng = RandomNumberGenerator { state: data_u32 };
|
||||||
let value = rng.gen();
|
let value = rng.gen();
|
||||||
GLOBAL_RNG.store(unsafe { core::mem::transmute(rng.state) }, Ordering::SeqCst);
|
GLOBAL_RNG.store(
|
||||||
|
unsafe { core::mem::transmute::<[u32; 4], u128>(rng.state) },
|
||||||
|
Ordering::SeqCst,
|
||||||
|
);
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue