xref: /DragonOS/kernel/src/arch/riscv64/rand.rs (revision f9fe30be89e89499aad4ef52b4648986bef5a7d8)
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