Skip to content

Commit b3f08c3

Browse files
committed
fix: rand() function
1 parent 60efb0e commit b3f08c3

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/types/topk.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <cstdint>
2626
#include <cstring>
2727
#include <memory>
28+
#include <random>
2829

2930
//-----------------------------------------------------------------------------
3031
// MurmurHash2 was written by Austin Appleby, and is placed in the public
@@ -207,7 +208,10 @@ void BlockSplitTopK::Add(const std::string &item, uint32_t increment, std::vecto
207208
pow(lookup_table[TOPK_DECAY_LOOKUP_TABLE - 1], (buckets[i][loc].count / (TOPK_DECAY_LOOKUP_TABLE - 1))) *
208209
lookup_table[buckets[i][loc].count % (TOPK_DECAY_LOOKUP_TABLE - 1)];
209210
}
210-
double chance = rand() / (double)RAND_MAX;
211+
std::random_device rd;
212+
std::mt19937 gen(rd());
213+
std::uniform_real_distribution<> dis(0.0, 1.0);
214+
double chance = dis(gen);
211215
if (chance < decay) {
212216
--buckets[i][loc].count;
213217
if (buckets[i][loc].count == 0) {

0 commit comments

Comments
 (0)