Skip to content

Commit

Permalink
Use rand() instead of random()
Browse files Browse the repository at this point in the history
Use rand() instead of random() cause the latter is not available
on Windows and postgres stopped backporting it with PG15.
Ideally we switch to the crypto functions added in PG15 but that
requires a bit more work and this is the minimal change required
to get it to build against PG15 on Windows.
  • Loading branch information
svenklemm committed Dec 20, 2022
1 parent b74f563 commit 7d1b74a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bgw/job_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ static float8
calculate_jitter_percent()
{
/* returns a number in the range [-0.125, 0.125] */
uint8 percent = random();
uint8 percent = rand();
return ldexp((double) (16 - (int) (percent % 32)), -7);
}

Expand Down Expand Up @@ -305,7 +305,7 @@ calculate_next_start_on_failure(TimestampTz finish_time, int consecutive_failure
MemoryContext oldctx;
/* 2^(consecutive_failures) - 1, at most 2^20 */
int64 max_slots = (INT64CONST(1) << (int64) multiplier) - INT64CONST(1);
int64 rand_backoff = random() % (max_slots * USECS_PER_SEC);
int64 rand_backoff = rand() % (max_slots * USECS_PER_SEC);

if (!IS_VALID_TIMESTAMP(finish_time))
{
Expand Down

0 comments on commit 7d1b74a

Please sign in to comment.