diff --git a/libretroshare/src/tests/general/random_test.cc b/libretroshare/src/tests/general/random_test.cc index 3edfb6e98..6232829ab 100644 --- a/libretroshare/src/tests/general/random_test.cc +++ b/libretroshare/src/tests/general/random_test.cc @@ -132,6 +132,7 @@ int main(int argc, char **argv) feenableexcept(FE_INVALID) ; feenableexcept(FE_DIVBYZERO) ; #endif + std::cerr << "Generating random 64 chars string (run that again to test that it's changing): " << RSRandom::random_alphaNumericString(64) << std::endl; int nt = 10 ; // number of threads. std::vector threads(nt,(myThread*)NULL) ; diff --git a/libretroshare/src/util/rsrandom.cc b/libretroshare/src/util/rsrandom.cc index b05a4e252..c1d346be9 100644 --- a/libretroshare/src/util/rsrandom.cc +++ b/libretroshare/src/util/rsrandom.cc @@ -1,10 +1,14 @@ #include +#include +#include #include "rsrandom.h" uint32_t RSRandom::index = 0 ; std::vector RSRandom::MT(RSRandom::N,0u) ; RsMutex RSRandom::rndMtx ; -static bool auto_seed = RSRandom::seed(time(NULL)) ; + +// If this does not compile on windows, use a ifdef to keep this on linux plz. +static bool auto_seed = RSRandom::seed( (time(NULL) + pthread_self()*0x1293fe + (getpid()^0x113ef76b))^0x18e34a12 ) ; bool RSRandom::seed(uint32_t s) { @@ -71,3 +75,13 @@ double RSRandom::random_f64() return random_u64() / (double)(~(uint64_t)0) ; } +std::string RSRandom::random_alphaNumericString(uint32_t len) +{ + std::string s = "" ; + + for(int i=0;i