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