We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1e0e7d8 commit c4d0535Copy full SHA for c4d0535
futures-util/src/async_await/random.rs
@@ -56,15 +56,22 @@ fn random() -> u64 {
56
57
#[cfg(not(feature = "std"))]
58
fn random() -> u64 {
59
- use core::sync::atomic::{AtomicU64, Ordering};
+ use core::sync::atomic::{AtomicUsize, Ordering};
60
61
- static RNG: AtomicU64 = AtomicU64::new(1);
+ static RNG: AtomicUsize = AtomicUsize::new(1);
62
63
let mut x = RNG.load(Ordering::Relaxed);
64
65
- x ^= x >> 12;
66
- x ^= x << 25;
67
- x ^= x >> 27;
+ if core::mem::size_of::<usize>() == 4 {
+ x ^= x << 13;
+ x ^= x >> 17;
68
+ x ^= x << 5;
69
+ } else if core::mem::size_of::<usize>() == 8 {
70
+ x ^= x >> 12;
71
+ x ^= x << 25;
72
+ x ^= x >> 27;
73
+ }
74
+
75
let result = x.wrapping_mul(0x2545_f491_4f6c_dd1d) as u64;
76
RNG.store(result, Ordering::Relaxed);
77
0 commit comments