xref: /DragonOS/kernel/src/arch/riscv64/rand.rs (revision 2b7818e80e00fcfe4d03533f587cc125ea5e4bec)

rand() -> usize1 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