Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit98c5065

Browse files
committed
Increase the number of different values used when seeding random().
When a backend process is forked, we initialize the system's random numbergenerator with srandom(). The seed used is derived from the backend's pidand the timestamp. However, we only used the microseconds part of thetimestamp, and it was XORed with the pid, so the total range of differentseed values chosen was 0-999999. That's quite limited.Change the code to also use the seconds part of the timestamp in the seed,and shift the microseconds so that all 32 bits of the seed are used.Honza Horak
1 parent75fdcec commit98c5065

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,9 +4033,9 @@ BackendRun(Port *port)
40334033
*/
40344034
random_seed=0;
40354035
random_start_time.tv_usec=0;
4036-
/* slightly hacky way toget integer microseconds part of timestamptz */
4036+
/* slightly hacky way toconvert timestamptz into integers */
40374037
TimestampDifference(0,port->SessionStartTime,&secs,&usecs);
4038-
srandom((unsignedint) (MyProcPid ^usecs));
4038+
srandom((unsignedint) (MyProcPid ^(usecs <<12) ^secs));
40394039

40404040
/*
40414041
* Now, build the argv vector that will be given to PostgresMain.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp