xref: /DragonOS/kernel/src/arch/riscv64/rand.rs (revision 886ce28516f9e3e5940840d1ae64ec3e9c8875fa)
1 pub fn rand() -> usize {
2     static mut SEED: u64 = 0xdead_beef_cafe_babe;
3     let mut buf = [0u8; size_of::<usize>()];
4     for x in buf.iter_mut() {
5         unsafe {
6             // from musl
7             SEED = SEED.wrapping_mul(0x5851_f42d_4c95_7f2d);
8             *x = (SEED >> 33) as u8;
9         }
10     }
11     let x: usize = unsafe { core::mem::transmute(buf) };
12     return x;
13 }
14