Improve utils::RandomString

Reviewers: dgleich

Reviewed By: dgleich

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1023
This commit is contained in:
florijan 2017-12-04 13:59:24 +01:00
parent 3c6306985d
commit e218bc1c69
2 changed files with 5 additions and 5 deletions

View File

@ -1,11 +1,11 @@
#pragma once
#include <stdlib.h>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <iostream>
#include <iterator>
#include <random>
#include <regex>
#include <sstream>
#include <string>
@ -210,9 +210,12 @@ inline std::string RandomString(size_t length) {
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
static thread_local std::mt19937 pseudo_rand_gen{std::random_device{}()};
static thread_local std::uniform_int_distribution<size_t> rand_dist{
0, strlen(charset) - 1};
std::string str(length, 0);
for (size_t i = 0; i < length; ++i)
str[i] = charset[rand() % strlen(charset)];
str[i] = charset[rand_dist(pseudo_rand_gen)];
return str;
}
} // namespace utils

View File

@ -1,5 +1,3 @@
#include <time.h>
#include <cstdio>
#include <experimental/filesystem>
#include <experimental/optional>
#include <functional>
@ -299,7 +297,6 @@ class Durability : public ::testing::Test {
durability_dir_ = tmp_dir_ / utils::RandomString(24);
snapshot_dir_ = durability_dir_ / durability::kSnapshotDir;
wal_dir_ = durability_dir_ / durability::kWalDir;
srand(time(NULL));
FLAGS_wal_rotate_ops_count = 1000;
CleanDurability();
}