X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=compat%2Fnrand48.c;h=67f3fdb8f9fd46efefdc7cf2242e157002d0498c;hb=dce22e6988beba8949e2973de710e7c272579be3;hp=020417e4cb9f993a009d13427822c616960fd15a;hpb=df9356f54bd6396447e2a465b8efda2fdbd21147;p=vlc diff --git a/compat/nrand48.c b/compat/nrand48.c index 020417e4cb..67f3fdb8f9 100644 --- a/compat/nrand48.c +++ b/compat/nrand48.c @@ -1,21 +1,21 @@ /***************************************************************************** - * nrand48.c: POSIX nrand48() replacement + * nrand48.c: POSIX erand48(), jrand48() and nrand48() replacements ***************************************************************************** * Copyright © 2010 Rémi Denis-Courmont * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ #ifdef HAVE_CONFIG_H @@ -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; }