File tree Expand file tree Collapse file tree 1 file changed +5
-16
lines changed
futures-util/src/async_await Expand file tree Collapse file tree 1 file changed +5
-16
lines changed Original file line number Diff line number Diff line change 1
1
use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
2
2
#[ cfg( feature = "std" ) ]
3
- use std:: {
4
- cell:: Cell ,
5
- collections:: hash_map:: DefaultHasher ,
6
- hash:: Hasher ,
7
- } ;
3
+ use std:: cell:: Cell ;
8
4
9
5
// Based on [Fisher–Yates shuffle].
10
6
//
@@ -32,17 +28,9 @@ fn random() -> usize {
32
28
// Any non-zero seed will do
33
29
let mut seed = 0 ;
34
30
while seed == 0 {
35
- let mut hasher = DefaultHasher :: new ( ) ;
36
- hasher. write_usize ( COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ) ;
37
- seed = hasher. finish ( ) ;
31
+ seed = COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
38
32
}
39
- seed as usize
40
- }
41
-
42
- #[ cfg( not( feature = "std" ) ) ]
43
- const fn prng_seed ( ) -> usize {
44
- // A deterministic seed is used in absense of TLS
45
- 42
33
+ seed
46
34
}
47
35
48
36
/// [xorshift*] is used on 64bit platforms.
@@ -98,7 +86,8 @@ fn random() -> usize {
98
86
99
87
#[ cfg( not( feature = "std" ) ) ]
100
88
fn rng ( ) -> usize {
101
- static RNG : AtomicUsize = AtomicUsize :: new ( prng_seed ( ) ) ;
89
+ // A deterministic seed is used in absense of TLS
90
+ static RNG : AtomicUsize = AtomicUsize :: new ( 42 ) ;
102
91
103
92
// Preemption here can cause multiple threads to observe repeated state
104
93
let ( x, res) = xorshift ( RNG . load ( Ordering :: Relaxed ) ) ;
You can’t perform that action at this time.
0 commit comments