aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-08-22 18:18:07 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-08-22 18:18:07 -0700
commitd231cb33833d89398935f6c11976c4607de9fc39 (patch)
tree451d9ec14dc90e9ee672af0446ed3a2df9a564ac
parentd14fa6d9156035b1c9edf00b8f4a7131c135f027 (diff)
use Math.random() in rand(). This gives properly random results, unlike before, but we now ignore the seed sadly
-rw-r--r--src/library.js25
1 files changed, 6 insertions, 19 deletions
diff --git a/src/library.js b/src/library.js
index cfa29c58..dda3e0a5 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3907,26 +3907,13 @@ LibraryManager.library = {
return limit;
},
- // A glibc-like implementation of the C random number generation functions:
- // http://pubs.opengroup.org/onlinepubs/000095399/functions/rand.html
- __rand_state: 42,
- srand__deps: ['__rand_state'],
- srand: function(seed) {
- // void srand(unsigned seed);
- ___rand_state = seed;
- },
- rand__deps: ['__rand_state'],
+ // Use browser's Math.random(). We can't set a seed, though.
+ srand: function(seed) {}, // XXX ignored
rand: function() {
- // int rand(void);
- ___rand_state = (1103515245 * ___rand_state + 12345) % 0x100000000;
- return ___rand_state & 0x7FFFFFFF;
- },
- rand_r: function(seed) {
- // int rand_r(unsigned *seed);
- var state = {{{ makeGetValue('seed', 0, 'i32') }}};
- state = (1103515245 * state + 12345) % 0x100000000;
- {{{ makeSetValue('seed', 0, 'state', 'i32') }}}
- return state & 0x7FFFFFFF;
+ return Math.floor(Math.random()*0x80000000);
+ },
+ rand_r: function(seed) { // XXX ignores the seed
+ return Math.floor(Math.random()*0x80000000);
},
realpath__deps: ['$FS', '__setErrNo'],