From 4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwenol=C3=A9=20Beauchesne?= Date: Wed, 4 Jun 2003 18:44:09 +0000 Subject: Import dietlibc 0.22 + other fixes for AMD64 --- mdk-stage1/dietlibc/lib/rand_r.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 mdk-stage1/dietlibc/lib/rand_r.c (limited to 'mdk-stage1/dietlibc/lib/rand_r.c') diff --git a/mdk-stage1/dietlibc/lib/rand_r.c b/mdk-stage1/dietlibc/lib/rand_r.c new file mode 100644 index 000000000..55f8303bc --- /dev/null +++ b/mdk-stage1/dietlibc/lib/rand_r.c @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002 Luc Van Oostenryck + + This is free software. You can redistribute and + modify it under the terms of the GNU General Public + Public License. +*/ + +#include +#include + +/* Knuth's TAOCP section 3.6 */ +#define M ((1U<<31) -1) +#define A 48271 +#define Q 44488 // M/A +#define R 3399 // M%A; R < Q !!! + +// FIXME: ISO C/SuS want a longer period + +int rand_r(unsigned int* seed) +{ int32_t X; + + X = *seed; + X = A*(X%Q) - R * (int32_t) (X/Q); + if (X < 0) + X += M; + + *seed = X; + return X; +} -- cgit v1.2.1