]> git.kaiwu.me - nginx.git/commitdiff
Win32: extended ngx_random() range to 0x7fffffff.
authorJ Carter <jordanc.carter@outlook.com>
Sat, 9 Dec 2023 08:38:14 +0000 (08:38 +0000)
committerJ Carter <jordanc.carter@outlook.com>
Sat, 9 Dec 2023 08:38:14 +0000 (08:38 +0000)
rand() is used on win32. RAND_MAX is implementation defined. win32's is
0x7fff.

Existing uses of ngx_random() rely upon 0x7fffffff range provided by
POSIX implementations of random().

src/os/win32/ngx_win32_config.h

index 406003a780413ca75e8931eecf55f88d60e16141..704561355c297308e00e38bc73406b26f2f932f4 100644 (file)
@@ -280,7 +280,11 @@ typedef int                 sig_atomic_t;
 
 #define NGX_HAVE_GETADDRINFO         1
 
-#define ngx_random               rand
+#define ngx_random()                                                          \
+    ((long) (0x7fffffff & ( ((uint32_t) rand() << 16)                         \
+                          ^ ((uint32_t) rand() << 8)                          \
+                          ^ ((uint32_t) rand()) )))
+
 #define ngx_debug_init()