-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrandom.js
More file actions
52 lines (44 loc) · 848 Bytes
/
random.js
File metadata and controls
52 lines (44 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// keyj
// mog
/*jslint devel: true, browser: true */
var Random = (function () {
"use strict";
var x = 2323233,
y = 8000085,
z = 1333337,
w = 4242424;
function seed(newX, newY, newZ, newW) {
x = newX;
y = newY;
z = newZ;
w = newW;
}
function xor128() {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = w ^ (w >>> 19) ^ (t ^ (t >>> 8));
return (w < 0) ? (w + 4294967296) : w;
}
function xor128Float() {
return (xor128() * (1 / 4294967296));
}
function range(min, max) {
return xor128Float() * (max - min + 1) + min;
}
function color() {
return "#" + ((1 << 24) * xor128Float() | 0).toString(16);
}
function uniqueID() {
return Math.random().toString(36).substr(2, 8);
}
return {
int: xor128,
float: xor128Float,
range: range,
color: color,
uniqueID: uniqueID,
seed: seed
};
}());