Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2000-06-09 22:50:05 +0400
committerJeff Johnston <jjohnstn@redhat.com>2000-06-09 22:50:05 +0400
commit46a43a99c6b835dd6f10e2fd4d24cd5c70a26691 (patch)
tree8d4dab67e74cfebee22703642dc0f7ff961a9db4 /newlib/libc/stdlib/rand.c
parentb6c40e83e9f6513e7aee7583a75bff4ec3892bed (diff)
Fri Jun 9 14:28:00 2000 Jeff Johnston <jjohnstn@cygnus.com>
* libc/include/sys/reent.h (_rand_next): Changed to unsigned long long and moved to end of _reent struct in _new union. (_REENT_INIT): Changed to move _rand_next initialization. * libc/stdlib/rand.c (rand): Changed to use unsigned long long linear congruential algorithm that is used by DJGPP.
Diffstat (limited to 'newlib/libc/stdlib/rand.c')
-rw-r--r--newlib/libc/stdlib/rand.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/newlib/libc/stdlib/rand.c b/newlib/libc/stdlib/rand.c
index 3d739efbc..4cf7f2932 100644
--- a/newlib/libc/stdlib/rand.c
+++ b/newlib/libc/stdlib/rand.c
@@ -78,9 +78,12 @@ _DEFUN (srand, (seed), unsigned int seed)
int
_DEFUN_VOID (rand)
{
- return ((_REENT->_new._reent._rand_next =
- _REENT->_new._reent._rand_next * 1103515245 + 12345 )
- & RAND_MAX );
+ /* This multiplier was obtained from Knuth, D.E., "The Art of
+ Computer Programming," Vol 2, Seminumerical Algorithms, Third
+ Edition, Addison-Wesley, 1998, p. 106 (line 26) & p. 108 */
+ _REENT->_new._reent._rand_next =
+ _REENT->_new._reent._rand_next * 6364136223846793005LL + 1;
+ return (int)((_REENT->_new._reent._rand_next >> 32) & RAND_MAX);
}
#endif /* _REENT_ONLY */