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