@@ -13,6 +13,8 @@ int main(int, char **) { return 0; }
13
13
#include < Common/Exception.h>
14
14
#include < Common/ThreadPool.h>
15
15
#include < Common/Stopwatch.h>
16
+ #include < Common/randomSeed.h>
17
+ #include < pcg_random.hpp>
16
18
#include < IO/BufferWithOwnMemory.h>
17
19
#include < IO/ReadHelpers.h>
18
20
#include < stdio.h>
@@ -52,10 +54,7 @@ void thread(int fd, int mode, size_t min_offset, size_t max_offset, size_t block
52
54
for (size_t i = 0 ; i < buffers_count; ++i)
53
55
buffers[i] = Memory<>(block_size, sysconf (_SC_PAGESIZE));
54
56
55
- drand48_data rand_data;
56
- timespec times;
57
- clock_gettime (CLOCK_THREAD_CPUTIME_ID, ×);
58
- srand48_r (times.tv_nsec , &rand_data);
57
+ pcg64_fast rng (randomSeed ());
59
58
60
59
size_t in_progress = 0 ;
61
60
size_t blocks_sent = 0 ;
@@ -82,12 +81,9 @@ void thread(int fd, int mode, size_t min_offset, size_t max_offset, size_t block
82
81
83
82
char * buf = buffers[i].data ();
84
83
85
- long rand_result1 = 0 ;
86
- long rand_result2 = 0 ;
87
- long rand_result3 = 0 ;
88
- lrand48_r (&rand_data, &rand_result1);
89
- lrand48_r (&rand_data, &rand_result2);
90
- lrand48_r (&rand_data, &rand_result3);
84
+ uint64_t rand_result1 = rng ();
85
+ uint64_t rand_result2 = rng ();
86
+ uint64_t rand_result3 = rng ();
91
87
92
88
size_t rand_result = rand_result1 ^ (rand_result2 << 22 ) ^ (rand_result3 << 43 );
93
89
size_t offset = min_offset + rand_result % ((max_offset - min_offset) / block_size) * block_size;
@@ -172,7 +168,7 @@ int mainImpl(int argc, char ** argv)
172
168
Stopwatch watch;
173
169
174
170
for (size_t i = 0 ; i < threads_count; ++i)
175
- pool.scheduleOrThrowOnError (std::bind (thread, fd, mode, min_offset, max_offset, block_size, buffers_count, count));
171
+ pool.scheduleOrThrowOnError ([=]{ thread ( fd, mode, min_offset, max_offset, block_size, buffers_count, count); } );
176
172
pool.wait ();
177
173
178
174
watch.stop ();
0 commit comments