X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=test%2Flib%2Frandom.hpp;h=322de6af91392b59fede7d91945039fcc299e6fb;hb=844026ddb563959b8327bff40b976c41644fa2d2;hp=18e518c34866073d9da897459e2112a8b7e145b7;hpb=d01f59eec297365fdbfeba38248245bf4e5d827a;p=awesomized%2Flibmemcached diff --git a/test/lib/random.hpp b/test/lib/random.hpp index 18e518c3..322de6af 100644 --- a/test/lib/random.hpp +++ b/test/lib/random.hpp @@ -1,26 +1,42 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include #include +#include #include #include #include #include +#include using namespace std; using kv_pair = pair; +extern mt19937_64 rnd_eng; +extern mutex rnd_mtx; + +void random_setup(); + template enable_if_t, T> random_num(T min, T max) { - using namespace chrono; - using rnd = mt19937; - using dst = uniform_int_distribution; - - auto time = duration_cast(system_clock::now().time_since_epoch()); - auto seed = static_cast(time.count() % numeric_limits::max()); - auto rgen = rnd{seed}; - return dst(min, max)(rgen); + lock_guard m{rnd_mtx}; + return uniform_int_distribution(min, max)(rnd_eng); } unsigned random_port(); @@ -30,10 +46,10 @@ char random_binary(); string random_binary_string(size_t len); char random_ascii(char min = '!', char max = '~'); string random_ascii_string(size_t len, char min = '!', char max = '~'); -kv_pair random_ascii_pair(size_t minlen = 1<<2, size_t maxlen = 1<<10); +kv_pair random_ascii_pair(size_t minlen = 1 << 2, size_t maxlen = 1 << 10); -template