From: Rémi Denis-Courmont Date: Sat, 6 Mar 2010 09:31:34 +0000 (+0200) Subject: Also provide erand48 and jrand48, they come almost for free X-Git-Tag: 1.1.0-pre1~483 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=d663d29a5802222f4034833d1e51c787e1788a9f;p=vlc Also provide erand48 and jrand48, they come almost for free --- diff --git a/compat/nrand48.c b/compat/nrand48.c index 020417e4cb..ff4e9b138d 100644 --- a/compat/nrand48.c +++ b/compat/nrand48.c @@ -1,5 +1,5 @@ /***************************************************************************** - * nrand48.c: POSIX nrand48() replacement + * nrand48.c: POSIX erand48(), jrand48() and nrand48() replacements ***************************************************************************** * Copyright © 2010 Rémi Denis-Courmont * @@ -24,7 +24,7 @@ #include -long nrand48 (unsigned short subi[3]) +static uint64_t iterate48 (unsigned short subi[3]) { const uint64_t a = UINT64_C(0x5DEECE66D); const unsigned c = 13; @@ -42,5 +42,21 @@ long nrand48 (unsigned short subi[3]) subi[1] = (x >> 16) & 0xFFFF; subi[2] = (x >> 0) & 0XFFFF; - return x >> 17; + return x; +} + +double erand48 (unsigned short subi[3]) +{ + uint64_t r = iterate48 (subi); + return ((double)r) / 281474976710655.; +} + +long jrand48 (unsigned short subi[3]) +{ + return ((int64_t)iterate48 (subi)) >> 16; +} + +long nrand48 (unsigned short subi[3]) +{ + return iterate48 (subi) >> 17; } diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h index 8e24e0f3c1..08a16ff950 100644 --- a/include/vlc_fixups.h +++ b/include/vlc_fixups.h @@ -241,6 +241,8 @@ struct pollfd /* Random numbers */ #ifndef HAVE_NRAND48 +double erand48 (unsigned short subi[3]); +long jrand48 (unsigned short subi[3]); long nrand48 (unsigned short subi[3]); #endif