diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2000-06-09 18:50:05 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2000-06-09 18:50:05 +0000 |
commit | 46a43a99c6b835dd6f10e2fd4d24cd5c70a26691 (patch) | |
tree | 8d4dab67e74cfebee22703642dc0f7ff961a9db4 /newlib | |
parent | b6c40e83e9f6513e7aee7583a75bff4ec3892bed (diff) | |
download | newlib-46a43a99c6b835dd6f10e2fd4d24cd5c70a26691.zip newlib-46a43a99c6b835dd6f10e2fd4d24cd5c70a26691.tar.gz newlib-46a43a99c6b835dd6f10e2fd4d24cd5c70a26691.tar.bz2 |
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')
-rw-r--r-- | newlib/ChangeLog | 8 | ||||
-rw-r--r-- | newlib/libc/include/sys/reent.h | 8 | ||||
-rw-r--r-- | newlib/libc/stdlib/rand.c | 9 |
3 files changed, 19 insertions, 6 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index a322e11..9ec544c 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,11 @@ +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. + Thu Jun 8 21:18:00 2000 Ranjith Kumaran <ranjith@cygnus.com> * libc/include/stdlib.h: Set RAND_MAX to __RAND_MAX. diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h index 1104936..d6aefed 100644 --- a/newlib/libc/include/sys/reent.h +++ b/newlib/libc/include/sys/reent.h @@ -177,11 +177,13 @@ struct _reent { struct { - unsigned int _rand_next; + unsigned int _unused_rand; char * _strtok_last; char _asctime_buf[26]; struct tm _localtime_buf; int _gamma_signgam; + unsigned long long _rand_next; + } _reent; /* Two next two fields were once used by malloc. They are no longer used. They are used to preserve the space used before so as to @@ -210,8 +212,8 @@ struct _reent #define _REENT_INIT(var) \ { 0, &var.__sf[0], &var.__sf[1], &var.__sf[2], 0, "", 0, "C", \ - 0, NULL, NULL, 0, NULL, NULL, 0, NULL, { {1, NULL, "", \ - { 0,0,0,0,0,0,0,0}, 0 } } } + 0, NULL, NULL, 0, NULL, NULL, 0, NULL, { {0, NULL, "", \ + { 0,0,0,0,0,0,0,0}, 0, 1} } } /* * All references to struct _reent are via this pointer. diff --git a/newlib/libc/stdlib/rand.c b/newlib/libc/stdlib/rand.c index 3d739ef..4cf7f29 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 */ |