@@ -83,29 +83,25 @@ __wt_random_init_seed(WT_SESSION_IMPL *session, WT_RAND_STATE volatile *rnd_stat
83
83
{
84
84
struct timespec ts ;
85
85
WT_RAND_STATE rnd ;
86
- uint32_t v ;
86
+ uintmax_t threadid ;
87
87
88
88
__wt_epoch (session , & ts );
89
+ __wt_thread_id (& threadid );
89
90
90
91
/*
91
- * Use this, instead of __wt_random_init if we need to vary the initial state of the RNG. This
92
- * is (currently) only used by test programs, where, for example, an initial set of test data is
92
+ * Use this, instead of __wt_random_init, to vary the initial state of the RNG. This is
93
+ * (currently) only used by test programs, where, for example, an initial set of test data is
93
94
* created by a single thread, and we want more variability in the initial state of the RNG.
94
95
*
95
- * Take the seconds and nanoseconds from the clock as seeds, and smear that value across the
96
- * value space, using algorithm "xor" from Marsaglia, "Xorshift RNGs".
96
+ * Take the seconds and nanoseconds from the clock together with the thread ID to generate a
97
+ * 64-bit seed, then smear that value using algorithm "xor" from Marsaglia, "Xorshift RNGs".
97
98
*/
98
- v = (uint32_t )ts .tv_sec ;
99
- v ^= v << 13 ;
100
- v ^= v >> 17 ;
101
- v ^= v << 5 ;
102
- M_W (rnd ) = v + 521288629 ;
103
-
104
- v = (uint32_t )ts .tv_nsec ;
105
- v ^= v << 13 ;
106
- v ^= v >> 17 ;
107
- v ^= v << 5 ;
108
- M_Z (rnd ) = v + 362436069 ;
99
+ M_W (rnd ) = (uint32_t )ts .tv_sec ^ 521288629 ;
100
+ M_Z (rnd ) = (uint32_t )ts .tv_nsec ^ 362436069 ;
101
+ rnd .v ^= (uint64_t )threadid ;
102
+ rnd .v ^= rnd .v << 13 ;
103
+ rnd .v ^= rnd .v >> 7 ;
104
+ rnd .v ^= rnd .v << 17 ;
109
105
110
106
* rnd_state = rnd ;
111
107
}
0 commit comments