Skip to content

Commit bd79c91

Browse files
authored
Use threadsafe randomizer (#13754)
1 parent 78fee80 commit bd79c91

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

ydb/library/workload/log/log.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
#include "log.h"
22
#include <util/generic/serialized_enum.h>
3+
#include <util/random/normal.h>
34
#include <util/random/random.h>
45
#include <util/datetime/base.h>
56

6-
#include <cmath>
7-
#include <iomanip>
8-
#include <string>
9-
#include <thread>
10-
#include <random>
11-
#include <sstream>
12-
#include <chrono>
13-
#include <format>
14-
157
namespace NYdbWorkload {
168

179
namespace NLog {
@@ -22,8 +14,6 @@ using TRow = TLogGenerator::TRow;
2214
TLogGenerator::TLogGenerator(const TLogWorkloadParams* params)
2315
: TBase(params)
2416
, TotalColumnsCnt(1 + Params.IntColumnsCnt + Params.StrColumnsCnt)
25-
, RandomDevice()
26-
, Mt19937(RandomDevice())
2717
{
2818
Y_ABORT_UNLESS(TotalColumnsCnt >= Params.KeyColumnsCnt);
2919
}
@@ -209,10 +199,9 @@ TVector<std::string> TLogGenerator::GetCleanPaths() const {
209199
TVector<TRow> TLogGenerator::GenerateRandomRows() {
210200
TVector<TRow> result(Params.RowsCnt);
211201

212-
std::normal_distribution<double> normal_distribution_generator(0, static_cast<double>(Params.TimestampStandardDeviationMinutes));
213202
for (size_t row = 0; row < Params.RowsCnt; ++row) {
214203
result[row].Ts = TInstant::Now();
215-
i64 millisecondsDiff = 60*1000*normal_distribution_generator(Mt19937);
204+
i64 millisecondsDiff = 60 * 1000 * NormalRandom(0., static_cast<double>(Params.TimestampStandardDeviationMinutes));
216205
if (millisecondsDiff >= 0) { // TDuration::MilliSeconds can't be negative for some reason...
217206
result[row].Ts = result[row].Ts + TDuration::MilliSeconds(millisecondsDiff);
218207
} else {

ydb/library/workload/log/log.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include <ydb/library/workload/abstract/workload_query_generator.h>
44

55
#include <cctype>
6-
#include <random>
7-
#include <sstream>
86

97
namespace NYdbWorkload {
108

@@ -102,9 +100,6 @@ class TLogGenerator final: public TWorkloadQueryGeneratorBase<TLogWorkloadParams
102100
TVector<TRow> GenerateRandomRows();
103101

104102
const ui64 TotalColumnsCnt;
105-
106-
std::random_device RandomDevice;
107-
std::mt19937 Mt19937;
108103
};
109104

110105
} // namespace NLog

0 commit comments

Comments
 (0)