This is a first go at a 'rand48' module which implements all the
*rand48* functions (including reentrant ones), copied from glibc.
Lightly tested on Linux & MinGW/Wine.
I'm not completely sure if this will work in the case of a platform
that has some but not all of the functions (Linux has all of them,
Windows has none of them). I'm pretty sure because of all the shared
internal state going on, that it's best to replace everything or
nothing, which is what I've tried to go for here, but perhaps not
successfully.
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
>From db48ece0351cd73991b5ce8107412d347b171378 Mon Sep 17 00:00:00 2001
From: Richard Jones <[EMAIL PROTECTED]>
Date: Thu, 23 Oct 2008 18:28:45 +0100
Subject: [PATCH] New module rand48.
---
lib/rand48.c | 675 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/stdlib.in.h | 126 +++++++++++
m4/rand48.m4 | 21 ++
m4/stdlib_h.m4 | 2 +
modules/rand48 | 24 ++
modules/stdlib | 2 +
6 files changed, 850 insertions(+), 0 deletions(-)
create mode 100644 lib/rand48.c
create mode 100644 m4/rand48.m4
create mode 100644 modules/rand48
diff --git a/lib/rand48.c b/lib/rand48.c
new file mode 100644
index 0000000..5a4caf9
--- /dev/null
+++ b/lib/rand48.c
@@ -0,0 +1,675 @@
+/* Copyright (C) 1995, 1996, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <math.h>
+#include <limits.h>
+
+/* Global state for non-reentrant functions. */
+struct drand48_data __drand48_data;
+
+int
+__drand48_iterate (xsubi, buffer)
+ unsigned short int xsubi[3];
+ struct drand48_data *buffer;
+{
+ uint64_t X;
+ uint64_t result;
+
+ /* Initialize buffer, if not yet done. */
+ if (buffer->__init == 0)
+ {
+ buffer->__a = 0x5deece66dull;
+ buffer->__c = 0xb;
+ buffer->__init = 1;
+ }
+
+ /* Do the real work. We choose a data type which contains at least
+ 48 bits. Because we compute the modulus it does not care how
+ many bits really are computed. */
+
+ X = (uint64_t) xsubi[2] << 32 | (uint32_t) xsubi[1] << 16 | xsubi[0];
+
+ result = X * buffer->__a + buffer->__c;
+
+ xsubi[0] = result & 0xffff;
+ xsubi[1] = (result >> 16) & 0xffff;
+ xsubi[2] = (result >> 32) & 0xffff;
+
+ return 0;
+}
+
+
+/* Copyright (C) 1995,1996,1997,1998,2001,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+double
+drand48 ()
+{
+ double result;
+
+ (void) erand48_r (__drand48_data.__x, &__drand48_data, &result);
+
+ return result;
+}
+
+
+/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+int
+drand48_r (buffer, result)
+ struct drand48_data *buffer;
+ double *result;
+{
+ return erand48_r (buffer->__x, buffer, result);
+}
+
+
+/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+double
+erand48 (xsubi)
+ unsigned short int xsubi[3];
+{
+ double result;
+
+ (void) erand48_r (xsubi, &__drand48_data, &result);
+
+ return result;
+}
+
+
+/* Copyright (C) 1995, 1997, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifdef HAVE_IEEE754_H
+# include <ieee754.h>
+#else
+# if defined(__i386__)
+
+#define IEEE754_DOUBLE_BIAS 0x3ff
+
+union ieee754_double
+{
+ double d;
+
+ /* This is only correct on i386 & x86-64 systems. */
+ struct
+ {
+ unsigned int mantissa1:32;
+ unsigned int mantissa0:20;
+ unsigned int exponent:11;
+ unsigned int negative:1;
+ } ieee;
+};
+# endif /* __i386__ */
+#endif /* !HAVE_IEEE754_H */
+
+int
+erand48_r (xsubi, buffer, result)
+ unsigned short int xsubi[3];
+ struct drand48_data *buffer;
+ double *result;
+{
+ union ieee754_double temp;
+
+ /* Compute next state. */
+ if (__drand48_iterate (xsubi, buffer) < 0)
+ return -1;
+
+ /* Construct a positive double with the 48 random bits distributed over
+ its fractional part so the resulting FP number is [0.0,1.0). */
+
+ temp.ieee.negative = 0;
+ temp.ieee.exponent = IEEE754_DOUBLE_BIAS;
+ temp.ieee.mantissa0 = (xsubi[2] << 4) | (xsubi[1] >> 12);
+ temp.ieee.mantissa1 = ((xsubi[1] & 0xfff) << 20) | (xsubi[0] << 4);
+
+ /* Please note the lower 4 bits of mantissa1 are always 0. */
+ *result = temp.d - 1.0;
+
+ return 0;
+}
+
+
+/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+long int
+jrand48 (xsubi)
+ unsigned short int xsubi[3];
+{
+ long int result;
+
+ (void) jrand48_r (xsubi, &__drand48_data, &result);
+
+ return result;
+}
+
+
+/* Copyright (C) 1995, 1997, 1998, 2001, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+int
+jrand48_r (xsubi, buffer, result)
+ unsigned short int xsubi[3];
+ struct drand48_data *buffer;
+ long int *result;
+{
+ /* Compute next state. */
+ if (__drand48_iterate (xsubi, buffer) < 0)
+ return -1;
+
+ /* Store the result. */
+ *result = (int32_t) ((xsubi[2] << 16) | xsubi[1]);
+
+ return 0;
+}
+
+
+/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+void
+lcong48 (param)
+ unsigned short int param[7];
+{
+ (void) lcong48_r (param, &__drand48_data);
+}
+
+
+/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+int
+lcong48_r (param, buffer)
+ unsigned short int param[7];
+ struct drand48_data *buffer;
+{
+ /* Store the given values. */
+ memcpy (buffer->__x, ¶m[0], sizeof (buffer->__x));
+ buffer->__a = ((uint64_t) param[5] << 32 | (uint32_t) param[4] << 16
+ | param[3]);
+ buffer->__c = param[6];
+ buffer->__init = 1;
+
+ return 0;
+}
+
+
+/* Copyright (C) 1995,1996,1997,1998,2001,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+long int
+lrand48 ()
+{
+ long int result;
+
+ (void) nrand48_r (__drand48_data.__x, &__drand48_data, &result);
+
+ return result;
+}
+
+
+/* Copyright (C) 1995,97,98,2001,02 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+int
+lrand48_r (buffer, result)
+ struct drand48_data *buffer;
+ long int *result;
+{
+ /* Be generous for the arguments, detect some errors. */
+ if (buffer == NULL)
+ return -1;
+
+ return nrand48_r (buffer->__x, buffer, result);
+}
+
+
+/* Copyright (C) 1995,1996,1997,1998,2001,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+long int
+mrand48 ()
+{
+ long int result;
+
+ (void) jrand48_r (__drand48_data.__x, &__drand48_data, &result);
+
+ return result;
+}
+
+
+/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+int
+mrand48_r (buffer, result)
+ struct drand48_data *buffer;
+ long int *result;
+{
+ /* Be generous for the arguments, detect some errors. */
+ if (buffer == NULL)
+ return -1;
+
+ return jrand48_r (buffer->__x, buffer, result);
+}
+
+
+/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+long int
+nrand48 (xsubi)
+ unsigned short int xsubi[3];
+{
+ long int result;
+
+ (void) nrand48_r (xsubi, &__drand48_data, &result);
+
+ return result;
+}
+
+
+/* Copyright (C) 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+int
+nrand48_r (xsubi, buffer, result)
+ unsigned short int xsubi[3];
+ struct drand48_data *buffer;
+ long int *result;
+{
+ /* Compute next state. */
+ if (__drand48_iterate (xsubi, buffer) < 0)
+ return -1;
+
+ /* Store the result. */
+ if (sizeof (unsigned short int) == 2)
+ *result = xsubi[2] << 15 | xsubi[1] >> 1;
+ else
+ *result = xsubi[2] >> 1;
+
+ return 0;
+}
+
+
+/* Copyright (C) 1995,1996,1997,1998,2001,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+unsigned short int *
+seed48 (seed16v)
+ unsigned short int seed16v[3];
+{
+ (void) seed48_r (seed16v, &__drand48_data);
+
+ return __drand48_data.__old_x;
+}
+
+
+/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+int
+seed48_r (seed16v, buffer)
+ unsigned short int seed16v[3];
+ struct drand48_data *buffer;
+{
+ /* Save old value at a private place to be used as return value. */
+ memcpy (buffer->__old_x, buffer->__x, sizeof (buffer->__x));
+
+ /* Install new state. */
+ buffer->__x[2] = seed16v[2];
+ buffer->__x[1] = seed16v[1];
+ buffer->__x[0] = seed16v[0];
+ buffer->__a = 0x5deece66dull;
+ buffer->__c = 0xb;
+ buffer->__init = 1;
+
+ return 0;
+}
+
+
+/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+void
+srand48 (seedval)
+ long seedval;
+{
+ (void) srand48_r (seedval, &__drand48_data);
+}
+
+
+/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, August 1995.
+
+ The GNU C Library 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.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+int
+srand48_r (seedval, buffer)
+ long int seedval;
+ struct drand48_data *buffer;
+{
+ /* The standards say we only have 32 bits. */
+ if (sizeof (long int) > 4)
+ seedval &= 0xffffffffl;
+
+ buffer->__x[2] = seedval >> 16;
+ buffer->__x[1] = seedval & 0xffffl;
+ buffer->__x[0] = 0x330e;
+
+ buffer->__a = 0x5deece66dull;
+ buffer->__c = 0xb;
+ buffer->__init = 1;
+
+ return 0;
+}
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index b44703b..9adfb23 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -217,6 +217,132 @@ extern int putenv (char *string);
#endif
+#if @GNULIB_RAND48@
+# if [EMAIL PROTECTED]@
+
+struct drand48_data
+ {
+ unsigned short int __x[3]; /* Current state. */
+ unsigned short int __old_x[3]; /* Old state. */
+ unsigned short int __c; /* Additive const. in congruential formula. */
+ unsigned short int __init; /* Flag for initializing. */
+ unsigned long long int __a; /* Factor in congruential formula. */
+ };
+
+double drand48 (void);
+int drand48_r (struct drand48_data *buffer, double *result);
+double erand48 ( unsigned short int xsubi[3]);
+int erand48_r (unsigned short int xsubi[3], struct drand48_data *buffer,
double *result);
+long int jrand48 (unsigned short int xsubi[3]);
+int jrand48_r (unsigned short int xsubi[3], struct drand48_data *buffer, long
int *result);
+void lcong48 (unsigned short int param[7]);
+int lcong48_r (unsigned short int param[7], struct drand48_data *buffer);
+long int lrand48 ();
+int lrand48_r (struct drand48_data *buffer, long int *result);
+long int mrand48 ();
+int mrand48_r (struct drand48_data *buffer, long int *result);
+long int nrand48 (unsigned short int xsubi[3]);
+int nrand48_r (unsigned short int xsubi[3], struct drand48_data *buffer, long
int *result);
+unsigned short int *seed48 (unsigned short int seed16v[3]);
+int seed48_r (unsigned short int seed16v[3], struct drand48_data *buffer);
+void srand48 (long seedval);
+int srand48_r (long int seedval, struct drand48_data *buffer);
+
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef drand48
+# define drand48() \
+ (GL_LINK_WARNING ("drand48 is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ drand48 ())
+# undef drand48_r
+# define drand48_r(b,r) \
+ (GL_LINK_WARNING ("drand48_r is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ drand48_r (b,r))
+# undef erand48
+# define erand48(a) \
+ (GL_LINK_WARNING ("erand48 is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ erand48 (a))
+# undef erand48_r
+# define erand48_r(a,b,r) \
+ (GL_LINK_WARNING ("erand48_r is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ erand48_r (a,b,r))
+# undef jrand48
+# define jrand48(a) \
+ (GL_LINK_WARNING ("jrand48 is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ jrand48 (a))
+# undef jrand48_r
+# define jrand48_r(a,b,r) \
+ (GL_LINK_WARNING ("drand48 is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ jrand48_r (a,b,r))
+# undef lcong48
+# define lcong48(p) \
+ (GL_LINK_WARNING ("lcong48 is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ lcong48 (p))
+# undef lcong48_r
+# define lcong48_r(p,b) \
+ (GL_LINK_WARNING ("lcong48_r is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ lcong48_r (p,b))
+# undef lrand48
+# define lrand48() \
+ (GL_LINK_WARNING ("lrand48 is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ lrand48 ())
+# undef lrand48_r
+# define lrand48_r(b,r) \
+ (GL_LINK_WARNING ("lrand48_r is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ lrand48_r (b,r))
+# undef mrand48
+# define mrand48() \
+ (GL_LINK_WARNING ("mrand48 is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ mrand48 ())
+# undef mrand48_r
+# define mrand48_r(b,r) \
+ (GL_LINK_WARNING ("mrand48_r is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ mrand48_r (b,r))
+# undef nrand48
+# define nrand48(a) \
+ (GL_LINK_WARNING ("nrand48 is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ nrand48 (a,))
+# undef nrand48_r
+# define nrand48_r(a,b,r) \
+ (GL_LINK_WARNING ("nrand48_r is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ nrand48_r (a,b,r))
+# undef seed48
+# define seed48(s) \
+ (GL_LINK_WARNING ("seed48 is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ seed48 (s))
+# undef seed48_r
+# define seed48_r(s,b) \
+ (GL_LINK_WARNING ("seed48_r is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ seed48_r (s,b))
+# undef srand48
+# define srand48(s) \
+ (GL_LINK_WARNING ("srand48 is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ srand48 (s))
+# undef srand48_r
+# define srand48_r(s,b) \
+ (GL_LINK_WARNING ("srand48_r is unportable - " \
+ "use gnulib module rand48 for portability"), \
+ srand48_r (s,b))
+#endif
+
+
#if @GNULIB_RANDOM_R@
# if [EMAIL PROTECTED]@
diff --git a/m4/rand48.m4 b/m4/rand48.m4
new file mode 100644
index 0000000..1e38ae1
--- /dev/null
+++ b/m4/rand48.m4
@@ -0,0 +1,21 @@
+# serial 1
+dnl Copyright (C) 2008 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_RAND48],
+[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+ AC_CHECK_FUNCS([drand48 erand48 lrand48 nrand48 mrand48 jrand48 srand48
seed48 lcong48 drand48_r erand48_r lrand48_r nrand48_r mrand48_r jrand48_r
srand48_r seed48_r lcong48_r])
+ if test $ac_cv_func_drand48 = no -o $ac_cv_func_erand48 = no -o
$ac_cv_func_lrand48 = no -o $ac_cv_func_nrand48 = no -o $ac_cv_func_mrand48 =
no -o $ac_cv_func_jrand48 = no -o $ac_cv_func_srand48 = no -o
$ac_cv_func_seed48 = no -o $ac_cv_func_lcong48 = no -o $ac_cv_func_drand48_r =
no -o $ac_cv_func_erand48_r = no -o $ac_cv_func_lrand48_r = no -o
$ac_cv_func_nrand48_r = no -o $ac_cv_func_mrand48_r = no -o
$ac_cv_func_jrand48_r = no -o $ac_cv_func_srand48_r = no -o
$ac_cv_func_seed48_r = no -o $ac_cv_func_lcong48_r = no ; then
+ HAVE_RAND48=0
+ AC_LIBOBJ([rand48])
+ gl_PREREQ_RAND48
+ fi
+])
+
+# Prerequisites of lib/rand48.c.
+AC_DEFUN([gl_PREREQ_RAND48], [
+ AC_CHECK_HEADERS([ieee754.h])
+])
diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4
index 3702d16..01b18db 100644
--- a/m4/stdlib_h.m4
+++ b/m4/stdlib_h.m4
@@ -28,6 +28,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP])
GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP])
GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV])
+ GNULIB_RAND48=0; AC_SUBST([GNULIB_RAND48])
GNULIB_RANDOM_R=0; AC_SUBST([GNULIB_RANDOM_R])
GNULIB_RPMATCH=0; AC_SUBST([GNULIB_RPMATCH])
GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV])
@@ -42,6 +43,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX])
HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP])
HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX])
+ HAVE_RAND48=1; AC_SUBST([HAVE_RAND48])
HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R])
HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH])
HAVE_SETENV=1; AC_SUBST([HAVE_SETENV])
diff --git a/modules/rand48 b/modules/rand48
new file mode 100644
index 0000000..7517db8
--- /dev/null
+++ b/modules/rand48
@@ -0,0 +1,24 @@
+Description:
+uniformly distributed random number generator functions
+
+Files:
+lib/rand48.c
+m4/rand48.m4
+
+Depends-on:
+stdlib
+
+configure.ac:
+gl_FUNC_RAND48
+gl_STDLIB_MODULE_INDICATOR([rand48])
+
+Makefile.am:
+
+Include:
+#include <stdlib.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Richard W.M. Jones
diff --git a/modules/stdlib b/modules/stdlib
index 715feea..6d532aa 100644
--- a/modules/stdlib
+++ b/modules/stdlib
@@ -33,6 +33,7 @@ stdlib.h: stdlib.in.h
-e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
-e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
-e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
+ -e 's|@''GNULIB_RAND48''@|$(GNULIB_RAND48)|g' \
-e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \
-e 's|@''GNULIB_RPMATCH''@|$(GNULIB_RPMATCH)|g' \
-e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \
@@ -46,6 +47,7 @@ stdlib.h: stdlib.in.h
-e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \
-e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
-e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \
+ -e 's|@''HAVE_RAND48''@|$(HAVE_RAND48)|g' \
-e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
-e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
-e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \
--
1.6.0.1