Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #197 from MathieuBordere/election-timeout-randomness
Browse files Browse the repository at this point in the history
uv: seed the PRNG
  • Loading branch information
Mathieu Borderé committed Apr 27, 2021
2 parents 269ac8b + 0dda754 commit 37af7cd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/uv.c
Expand Up @@ -594,7 +594,12 @@ static raft_time uvTime(struct raft_io *io)
/* Implementation of raft_io->random. */
static int uvRandom(struct raft_io *io, int min, int max)
{
(void)io;
static bool initialized = false;
if (!initialized) {
struct uv *uv = io->impl;
srand((unsigned)uv_now(uv->loop) + (unsigned)uv->id);
initialized = true;
}
return min + (abs(rand()) % (max - min));
}

Expand Down

0 comments on commit 37af7cd

Please sign in to comment.