1use core::{
4 ffi::{c_int, c_long, c_uint},
5 sync::atomic::{AtomicU64, Ordering::SeqCst},
6};
7
8static SEED: AtomicU64 = AtomicU64::new(0xa2ce_a2ce);
9
10#[unsafe(no_mangle)]
12pub unsafe extern "C" fn srand(seed: c_uint) {
13 SEED.store(seed.wrapping_sub(1) as u64, SeqCst);
14}
15
16#[unsafe(no_mangle)]
18pub unsafe extern "C" fn rand() -> c_int {
19 let new_seed = SEED.load(SeqCst).wrapping_mul(6364136223846793005) + 1;
20 SEED.store(new_seed, SeqCst);
21 (new_seed >> 33) as c_int
22}
23
24#[unsafe(no_mangle)]
26pub unsafe extern "C" fn random() -> c_long {
27 let new_seed = SEED.load(SeqCst).wrapping_mul(6364136223846793005) + 1;
28 SEED.store(new_seed, SeqCst);
29 new_seed as c_long
30}