chrome v8 MathRandom
Showing
1 changed file
with
17 additions
and
0 deletions
1 | /** | 1 | /** |
2 | * chrome v8 实现 | ||
3 | */ | ||
4 | /* | ||
5 | // ECMA 262 - 15.8.2.14 | ||
6 | var rngstate; // Initialized to a Uint32Array during genesis. | ||
7 | function MathRandom() { | ||
8 | var r0 = (MathImul(18030, rngstate[0] & 0xFFFF) + (rngstate[0] >>> 16)) | 0; | ||
9 | rngstate[0] = r0; | ||
10 | var r1 = (MathImul(36969, rngstate[1] & 0xFFFF) + (rngstate[1] >>> 16)) | 0; | ||
11 | rngstate[1] = r1; | ||
12 | var x = ((r0 << 16) + (r1 & 0xFFFF)) | 0; | ||
13 | // Division by 0x100000000 through multiplication by reciprocal. | ||
14 | return (x < 0 ? (x + 0x100000000) : x) * 2.3283064365386962890625e-10; | ||
15 | } | ||
16 | */ | ||
17 | |||
18 | /** | ||
2 | * 取范围内随机整数 | 19 | * 取范围内随机整数 |
3 | * @param {number} minNum | 20 | * @param {number} minNum |
4 | * @param {number} maxNum | 21 | * @param {number} maxNum | ... | ... |
-
Please register or sign in to post a comment