diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/library.js | 25 |
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'], |