Add overall code reformatting

This commit is contained in:
Christoph Diehl 2017-04-22 23:07:29 +03:00
parent 93d5fec51a
commit 6654cf857e
12 changed files with 248 additions and 212 deletions

View File

@ -1,14 +1,14 @@
var Logger = (function () {
let color = {
red: "\033[1;31m",
green: "\033[1;32m",
clear: "\033[0m"
red: "\033[1;31m",
green: "\033[1;32m",
clear: "\033[0m"
};
if (platform.isWindows) {
color = {
red: "",
green: "",
clear: ""
red: "",
green: "",
clear: ""
};
}
@ -30,31 +30,31 @@ var Logger = (function () {
}
function dump(msg) {
console(msg);
console(msg);
}
function testcase(msg) {
dump("/*L*/ " + JSON.stringify(msg) + "\n");
dump("/*L*/ " + JSON.stringify(msg) + "\n");
}
function dumpln(msg) {
dump(msg + "\n");
dump(msg + "\n");
}
function error(msg) {
dumpln(color.red + msg + color.clear);
dumpln(color.red + msg + color.clear);
}
function JSError(msg) {
error(comment(msg))
error(comment(msg))
}
function comment(msg) {
return "/* " + msg + " */";
return "/* " + msg + " */";
}
function separator() {
dumpln(color.green + sep + color.clear);
dumpln(color.green + sep + color.clear);
}
return {

View File

@ -1,5 +1,5 @@
make.colors = {
colors: function() {
colors: function () {
return random.pick([
make.colors.colorRGB,
make.colors.colorHSL,
@ -7,9 +7,9 @@ make.colors = {
]);
},
colorRGB: function() {
colorRGB: function () {
let values;
switch (random.number(4)) {
case 0:
// Rgb functional notation
@ -34,10 +34,10 @@ make.colors = {
}
},
colorHSL: function() {
colorHSL: function () {
let values, opt;
switch(random.number(4)) {
switch (random.number(4)) {
case 0:
values = [random.number(255), "%" + random.number(255), "%" + random.number(255)];
return "hsl(" + values.join(',') + ")";
@ -54,7 +54,7 @@ make.colors = {
}
},
colorKeywords: function() {
colorKeywords: function () {
return random.pick([
"lime", "red", "blue", "invert", "currentColor", "ActiveBorder", "ActiveCaption",
"AppWorkspace", "Background", "ButtonFace", "ButtonHighlight", "ButtonShadow",

View File

@ -1,20 +1,20 @@
make.fonts = {
fontStyles: function() {
fontStyles: function () {
return ["italic", "normal", "oblique", "inherit"];
},
fontVariants: function() {
fontVariants: function () {
return ["normal", "small-caps", "inherit"];
},
fontWeights: function() {
fontWeights: function () {
return ["normal", "bold", "bolder", "lighter"];
},
fontSizeAbsolute: function() {
fontSizeAbsolute: function () {
return ["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"];
},
fontFamiliesGeneric: function() {
fontFamiliesGeneric: function () {
return ["serif", "sans-serif", "cursive", "fantasy", "monospace"];
},
fontFamilies: function() {
fontFamilies: function () {
return ["'Times New Roman'", "Arial", "Courier", "Helvetica"];
},
fontFamily: function () {

View File

@ -1,5 +1,5 @@
make.network = {
sdp: function() {
sdp: function () {
// session description protocol template
return [
"v=0",
@ -34,36 +34,42 @@ make.network = {
"a=candidate:0 2 UDP 2113601790 192.168.129.33 62658 typ host",
].join("\n");
},
PeerConnectionProtocols: function() {
PeerConnectionProtocols: function () {
return ["turn", "turns", "stun", "stuns"]
},
randomIPv4: function() {
randomIPv4: function () {
return random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.numbers.number]);
random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.numbers.number]);
},
randomIPv6: function() {
return "[" + make.stringFromBlocks([":", function() { return make.strings.digitsHex(random.range(1, 4)) }]) + "]"
randomIPv6: function () {
return "[" + make.stringFromBlocks([":", function () {
return make.strings.digitsHex(random.range(1, 4))
}]) + "]"
},
goodHostnames: function() { return [
"0.0.0.0",
"127.0.0.1:8080",
]},
badHostnames: function() { return [
"google.org:8080",
"::1",
"[::192.9.5.5]:42",
"2001:db8:85a3::8a2e:370:3478",
"2001:db8:85a3:0:0:8a2e:370:3478",
"::ffff:192.0.2.1",
"0000:0000:0000:0000:0000:0000:0000:0001",
"::192.0.2.128",
"::ffff:192.0.2.128",
"2001:db8::1:2",
"2001:db8::1:1:1:1:1"
]},
randomBitmask: function(list) {
goodHostnames: function () {
return [
"0.0.0.0",
"127.0.0.1:8080",
]
},
badHostnames: function () {
return [
"google.org:8080",
"::1",
"[::192.9.5.5]:42",
"2001:db8:85a3::8a2e:370:3478",
"2001:db8:85a3:0:0:8a2e:370:3478",
"::ffff:192.0.2.1",
"0000:0000:0000:0000:0000:0000:0000:0001",
"::192.0.2.128",
"::ffff:192.0.2.128",
"2001:db8::1:2",
"2001:db8::1:1:1:1:1"
]
},
randomBitmask: function (list) {
if (list.length <= 1) {
return list.join("");
}

View File

@ -5,16 +5,25 @@ make.numbers = {
float: function () {
let n;
if (random.chance(32)) {
switch(random.number(4)) {
case 0: n = random.range(Number.MAX_VALUE, Number.MIN_VALUE); break;
case 1: n = Math.pow(10, 1) / Math.pow(10, random.number(307)); break;
case 2: n = Math.pow(2, random.float() * random.float() * 64); break;
case 3: n = Math.pow(10, random.range(1, 9)) / Math.pow(10, random.range(1, 9)); break;
switch (random.number(4)) {
case 0:
n = random.range(Number.MAX_VALUE, Number.MIN_VALUE);
break;
case 1:
n = Math.pow(10, 1) / Math.pow(10, random.number(307));
break;
case 2:
n = Math.pow(2, random.float() * random.float() * 64);
break;
case 3:
n = Math.pow(10, random.range(1, 9)) / Math.pow(10, random.range(1, 9));
break;
}
return n;
}
switch (random.number(6)) {
default: n = random.float();
default:
n = random.float();
}
return n;
},
@ -37,7 +46,7 @@ make.numbers = {
let value = random.choose([
[10, make.numbers.float],
[10, [make.numbers.rangeNumber, make.numbers.tinyNumber]],
[ 1, Make.numbers.unsignedNumber]
[1, Make.numbers.unsignedNumber]
]);
return random.chance(10) ? -value : value;
}

View File

@ -1,5 +1,5 @@
make.shaders = {
fragment1: function() {
fragment1: function () {
return [
[
"#ifdef GL_ES",
@ -7,7 +7,7 @@ make.shaders = {
"#endif",
"varying vec4 vColor;",
"void main() {",
"gl_FragColor=vColor;",
"gl_FragColor=vColor;",
"}",
],
[
@ -15,8 +15,8 @@ make.shaders = {
"varying highp vec3 vLighting;",
"uniform sampler2D uSampler;",
"void main(void) {",
"highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));",
"gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);",
"highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));",
"gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);",
"}"
]
]
@ -28,8 +28,8 @@ make.shaders = {
"attribute vec4 aColor;",
"varying vec4 vColor;",
"void main(){",
"vColor=aColor;",
"gl_Position=aVertex;",
"vColor=aColor;",
"gl_Position=aVertex;",
"}",
],
[
@ -42,27 +42,27 @@ make.shaders = {
"varying highp vec2 vTextureCoord;",
"varying highp vec3 vLighting;",
"void main(void) {",
"gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);",
"vTextureCoord = aTextureCoord;",
"highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);",
"highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);",
"highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);",
"highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);",
"highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);",
"vLighting = ambientLight + (directionalLightColor * directional);",
"gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);",
"vTextureCoord = aTextureCoord;",
"highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);",
"highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);",
"highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);",
"highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);",
"highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);",
"vLighting = ambientLight + (directionalLightColor * directional);",
"}"
]
]
},
fragment2: function() {
fragment2: function () {
return [
[
"varying highp vec2 vTextureCoord;",
"varying highp vec3 vLighting;",
"uniform sampler2D uSampler;",
"void main(void) {",
"highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));",
"gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);",
"highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));",
"gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);",
"}"
],
[
@ -74,19 +74,19 @@ make.shaders = {
"varying vec3 varyingNormal;",
"varying vec2 varyingUV;",
"void main(void) {",
"vec3 albedo=texture2D(albedoMap,varyingUV).rgb;",
"vec3 normal=texture2D(normalMap,varyingUV).rgb*2.0-1.0;",
"float specularFactor=pow((albedo.r+albedo.g+albedo.b)*0.33,2.0);",
"float specularHardness=2.0;",
"vec3 spaceNormal=varyingTangent*normal.x+varyingBitangent*normal.y+varyingNormal*normal.z;",
"gl_FragData[0]=vec4(albedo,1.0);",
"gl_FragData[1]=vec4(spaceNormal*0.5 +0.5,1.0);",
"gl_FragData[2]=vec4(specularFactor,specularHardness*0.1,0.0,1.0);",
"vec3 albedo=texture2D(albedoMap,varyingUV).rgb;",
"vec3 normal=texture2D(normalMap,varyingUV).rgb*2.0-1.0;",
"float specularFactor=pow((albedo.r+albedo.g+albedo.b)*0.33,2.0);",
"float specularHardness=2.0;",
"vec3 spaceNormal=varyingTangent*normal.x+varyingBitangent*normal.y+varyingNormal*normal.z;",
"gl_FragData[0]=vec4(albedo,1.0);",
"gl_FragData[1]=vec4(spaceNormal*0.5 +0.5,1.0);",
"gl_FragData[2]=vec4(specularFactor,specularHardness*0.1,0.0,1.0);",
"}"
]
]
},
vertex2: function() {
vertex2: function () {
return [
[
"attribute highp vec3 aVertexNormal;",
@ -98,14 +98,14 @@ make.shaders = {
"varying highp vec2 vTextureCoord;",
"varying highp vec3 vLighting;",
"void main(void) {",
"gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);",
"vTextureCoord = aTextureCoord;",
"highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);",
"highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);",
"highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);",
"highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);",
"highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);",
"vLighting = ambientLight + (directionalLightColor * directional);",
"gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);",
"vTextureCoord = aTextureCoord;",
"highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);",
"highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);",
"highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);",
"highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);",
"highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);",
"vLighting = ambientLight + (directionalLightColor * directional);",
"}"
],
[
@ -122,17 +122,17 @@ make.shaders = {
"varying vec3 varyingNormal;",
"varying vec2 varyingUV;",
"void main(void){",
"gl_Position=viewMatrix*(modelMatrix*vec4(vertexPosition,1.0));",
"gl_Position.xy=gl_Position.xy*0.5+(float(gl_InstanceID)-0.5);",
"varyingTangent=(modelMatrix*vec4(vertexTangent,0.0)).xyz;",
"varyingBitangent=(modelMatrix*vec4(vertexBitangent,0.0)).xyz;",
"varyingNormal=(modelMatrix*vec4(vertexNormal,0.0)).xyz;",
"varyingUV = vertexUV;",
"gl_Position=viewMatrix*(modelMatrix*vec4(vertexPosition,1.0));",
"gl_Position.xy=gl_Position.xy*0.5+(float(gl_InstanceID)-0.5);",
"varyingTangent=(modelMatrix*vec4(vertexTangent,0.0)).xyz;",
"varyingBitangent=(modelMatrix*vec4(vertexBitangent,0.0)).xyz;",
"varyingNormal=(modelMatrix*vec4(vertexNormal,0.0)).xyz;",
"varyingUV = vertexUV;",
"}"
]
]
]
},
shaderPair: function(v, f) {
shaderPair: function (v, f) {
let i = random.number(v.length);
return {
vertex: utils.common.quote(v[i].join("\n")),

View File

@ -26,7 +26,7 @@ make.text = {
"en-US", "en", "de"
]);
},
layoutCharCodes: function() {
layoutCharCodes: function () {
return random.pick([
0, // null
160, // non-breaking space
@ -96,73 +96,91 @@ make.text = {
},
// http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt
unicodeCombiningCharacters: function() { return random.item([
[0x0300, 0x036F], // Combining Diacritical Marks
[0x0483, 0x0489],
[0x07EB, 0x07F3],
[0x135D, 0x135F],
[0x1A7F, 0x1A7F],
[0x1B6B, 0x1B73],
[0x1DC0, 0x1DFF], // Combining Diacritical Marks Supplement
[0x20D0, 0x2DFF],
[0x3099, 0x309A],
[0xA66F, 0xA6F1],
[0xA8E0, 0xA8F1],
[0xFE20, 0xFE26], // Combining Half Marks
[0x101FD, 0x101FD],
[0x1D165, 0x1D169],
[0x1D16D, 0x1D172],
[0x1D17B, 0x1D18B],
[0x1D1AA, 0x1D1AD],
[0x1D242, 0x1D244]
])},
unicodeBMP: function() { return random.item([
// BMP = Basic Multilingual Plane
[0x0000, 0xFFFF]
])},
unicodeSMP: function() { return random.item([
// SMP = Supplementary Multilingual Plane
[0x10000, 0x13FFF],
[0x16000, 0x16FFF],
[0x1B000, 0x1BFFF],
[0x1D000, 0x1DFFF],
[0x1F000, 0x1FFFF]
])},
unicodeSIP: function() { return random.item([
// SIP = Supplementary Ideographic Plane
[0x20000, 0x2BFFF],
[0x2F000, 0x2FFFF]
])},
unicodeSSP: function() { return random.item([
// SSP = Supplementary Special-purpose Plane
[0xE0000, 0xE0FFF]
])},
registeredFontFeatures: function() { return random.pick([
'aalt', 'abvf', 'abvm', 'abvs', 'afrc', 'akhn', 'blwf', 'blwm', 'blws',
'calt', 'case', 'ccmp', 'cfar', 'cjct', 'clig', 'cpct', 'cpsp', 'cswh',
'curs', 'cv01-cv99', 'c2pc', 'c2sc', 'dist', 'dlig', 'dnom', 'expt',
'falt', 'fin2', 'fin3', 'fina', 'frac', 'fwid', 'half', 'haln', 'halt',
'hist', 'hkna', 'hlig', 'hngl', 'hojo', 'hwid', 'init', 'isol', 'ital',
'jalt', 'jp78', 'jp83', 'jp90', 'jp04', 'kern', 'lfbd', 'liga', 'ljmo',
'lnum', 'locl', 'ltra', 'ltrm', 'mark', 'med2', 'medi', 'mgrk', 'mkmk',
'mset', 'nalt', 'nlck', 'nukt', 'numr', 'onum', 'opbd', 'ordn', 'ornm',
'palt', 'pcap', 'pkna', 'pnum', 'pref', 'pres', 'pstf', 'psts', 'pwid',
'qwid', 'rand', 'rkrf', 'rlig', 'rphf', 'rtbd', 'rtla', 'rtlm', 'ruby',
'salt', 'sinf', 'size', 'smcp', 'smpl', 'ss01', 'ss02', 'ss03', 'ss04',
'ss05', 'ss06', 'ss07', 'ss08', 'ss09', 'ss10', 'ss11', 'ss12', 'ss13',
'ss14', 'ss15', 'ss16', 'ss17', 'ss18', 'ss19', 'ss20', 'subs', 'sups',
'swsh', 'titl', 'tjmo', 'tnam', 'tnum', 'trad', 'twid', 'unic', 'valt',
'vatu', 'vert', 'vhal', 'vjmo', 'vkna', 'vkrn', 'vpal', 'vrt2', 'zero'
])},
assignmentOperator: function() { return random.pick([
"=", "-=", "+=", "*=", "/="
])},
arithmeticOperator: function() { return random.pick([
"%", "-", "+", "*", "/"
])},
currency: function() { return random.pick([
// https://en.wikipedia.org/wiki/ISO_4217
"USD", "USS", "USN", "EUR", "CHF", "GBP", "XAG", "XBA", "XBB", "XBC",
"XBD", "XSU", "XTS", "XXX",
])},
unicodeCombiningCharacters: function () {
return random.item([
[0x0300, 0x036F], // Combining Diacritical Marks
[0x0483, 0x0489],
[0x07EB, 0x07F3],
[0x135D, 0x135F],
[0x1A7F, 0x1A7F],
[0x1B6B, 0x1B73],
[0x1DC0, 0x1DFF], // Combining Diacritical Marks Supplement
[0x20D0, 0x2DFF],
[0x3099, 0x309A],
[0xA66F, 0xA6F1],
[0xA8E0, 0xA8F1],
[0xFE20, 0xFE26], // Combining Half Marks
[0x101FD, 0x101FD],
[0x1D165, 0x1D169],
[0x1D16D, 0x1D172],
[0x1D17B, 0x1D18B],
[0x1D1AA, 0x1D1AD],
[0x1D242, 0x1D244]
])
},
unicodeBMP: function () {
return random.item([
// BMP = Basic Multilingual Plane
[0x0000, 0xFFFF]
])
},
unicodeSMP: function () {
return random.item([
// SMP = Supplementary Multilingual Plane
[0x10000, 0x13FFF],
[0x16000, 0x16FFF],
[0x1B000, 0x1BFFF],
[0x1D000, 0x1DFFF],
[0x1F000, 0x1FFFF]
])
},
unicodeSIP: function () {
return random.item([
// SIP = Supplementary Ideographic Plane
[0x20000, 0x2BFFF],
[0x2F000, 0x2FFFF]
])
},
unicodeSSP: function () {
return random.item([
// SSP = Supplementary Special-purpose Plane
[0xE0000, 0xE0FFF]
])
},
registeredFontFeatures: function () {
return random.pick([
'aalt', 'abvf', 'abvm', 'abvs', 'afrc', 'akhn', 'blwf', 'blwm', 'blws',
'calt', 'case', 'ccmp', 'cfar', 'cjct', 'clig', 'cpct', 'cpsp', 'cswh',
'curs', 'cv01-cv99', 'c2pc', 'c2sc', 'dist', 'dlig', 'dnom', 'expt',
'falt', 'fin2', 'fin3', 'fina', 'frac', 'fwid', 'half', 'haln', 'halt',
'hist', 'hkna', 'hlig', 'hngl', 'hojo', 'hwid', 'init', 'isol', 'ital',
'jalt', 'jp78', 'jp83', 'jp90', 'jp04', 'kern', 'lfbd', 'liga', 'ljmo',
'lnum', 'locl', 'ltra', 'ltrm', 'mark', 'med2', 'medi', 'mgrk', 'mkmk',
'mset', 'nalt', 'nlck', 'nukt', 'numr', 'onum', 'opbd', 'ordn', 'ornm',
'palt', 'pcap', 'pkna', 'pnum', 'pref', 'pres', 'pstf', 'psts', 'pwid',
'qwid', 'rand', 'rkrf', 'rlig', 'rphf', 'rtbd', 'rtla', 'rtlm', 'ruby',
'salt', 'sinf', 'size', 'smcp', 'smpl', 'ss01', 'ss02', 'ss03', 'ss04',
'ss05', 'ss06', 'ss07', 'ss08', 'ss09', 'ss10', 'ss11', 'ss12', 'ss13',
'ss14', 'ss15', 'ss16', 'ss17', 'ss18', 'ss19', 'ss20', 'subs', 'sups',
'swsh', 'titl', 'tjmo', 'tnam', 'tnum', 'trad', 'twid', 'unic', 'valt',
'vatu', 'vert', 'vhal', 'vjmo', 'vkna', 'vkrn', 'vpal', 'vrt2', 'zero'
])
},
assignmentOperator: function () {
return random.pick([
"=", "-=", "+=", "*=", "/="
])
},
arithmeticOperator: function () {
return random.pick([
"%", "-", "+", "*", "/"
])
},
currency: function () {
return random.pick([
// https://en.wikipedia.org/wiki/ISO_4217
"USD", "USS", "USN", "EUR", "CHF", "GBP", "XAG", "XBA", "XBB", "XBC",
"XBD", "XSU", "XTS", "XXX",
])
},
};

View File

@ -1,5 +1,5 @@
make.types = {
random: function() {
random: function () {
return random.item([
"true",
"null",

View File

@ -9,15 +9,15 @@
*
*/
function MersenneTwister()
{
function MersenneTwister() {
const N = 624;
const M = 397;
const UPPER_MASK = 0x80000000;
const LOWER_MASK = 0x7fffffff;
const MAG01 = new Int32Array([0, 0x9908b0df]);
let mt = new Int32Array(N); /* the array for the state vector */
let mt = new Int32Array(N);
/* the array for the state vector */
let mti = 625;
this.seed = function (s) {
@ -27,28 +27,28 @@ function MersenneTwister()
}
};
this.export_state = function() {
this.export_state = function () {
return [mt, mti];
};
this.import_state = function(s) {
this.import_state = function (s) {
mt = s[0];
mti = s[1];
};
this.export_mta = function() {
this.export_mta = function () {
return mt;
};
this.import_mta = function(_mta) {
this.import_mta = function (_mta) {
mt = _mta;
};
this.export_mti = function() {
this.export_mti = function () {
return mti;
};
this.import_mti = function(_mti) {
this.import_mti = function (_mti) {
mti = _mti;
};
@ -56,16 +56,16 @@ function MersenneTwister()
let y, kk;
if (mti >= N) { /* generate N words at one time */
for (kk = 0; kk < N-M; kk++) {
y = ((mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK));
mt[kk] = (mt[kk+M] ^ (y >>> 1) ^ MAG01[y & 0x1]);
for (kk = 0; kk < N - M; kk++) {
y = ((mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK));
mt[kk] = (mt[kk + M] ^ (y >>> 1) ^ MAG01[y & 0x1]);
}
for (; kk < N-1; kk++) {
y = ((mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK));
mt[kk] = (mt[kk+(M-N)] ^ (y >>> 1) ^ MAG01[y & 0x1]);
for (; kk < N - 1; kk++) {
y = ((mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK));
mt[kk] = (mt[kk + (M - N)] ^ (y >>> 1) ^ MAG01[y & 0x1]);
}
y = ((mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK));
mt[N-1] = (mt[M-1] ^ (y >>> 1) ^ MAG01[y & 0x1]);
y = ((mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK));
mt[N - 1] = (mt[M - 1] ^ (y >>> 1) ^ MAG01[y & 0x1]);
mti = 0;
}

View File

@ -2,9 +2,9 @@ var random = {
twister: null,
/**
* Must be called before any other methods can be called to initialize MersenneTwister.
* @param {number|null|undefined} seed Value to initialize MersenneTwister.
*/
* Must be called before any other methods can be called to initialize MersenneTwister.
* @param {number|null|undefined} seed Value to initialize MersenneTwister.
*/
init: function (seed) {
if (seed == null || seed === undefined) {
seed = new Date().getTime();
@ -21,10 +21,10 @@ var random = {
limit = 0xffffffff;
}
let x = (0x100000000 / limit) >>> 0,
y = (x * limit) >>> 0, r;
y = (x * limit) >>> 0, r;
do {
r = this.twister.int32();
} while(y && r >= y);
} while (y && r >= y);
return (r / x) >>> 0;
},
float: function () {
@ -39,7 +39,7 @@ var random = {
}
return this.number(limit - start + 1) + start;
},
ludOneTo: function(limit) {
ludOneTo: function (limit) {
// Returns a float in [1, limit]. The logarithm has uniform distribution.
return Math.exp(this.float() * Math.log(limit));
},

View File

@ -1,5 +1,5 @@
utils.block = {
block: function(list, optional) {
block: function (list, optional) {
if (optional == true) {
if (random.chance(6)) {
return '';
@ -16,7 +16,7 @@ utils.block = {
if (typeof(item) == "string") {
return item;
}
if (item instanceof(Array)) {
if (item instanceof (Array)) {
let s = "";
for (let i = 0; i < item.length; i++) {
s += go_deeper(item[i]);

View File

@ -11,7 +11,7 @@ utils.script = {
return "(" + params.join(", ") + ")";
},
methodCall: function (objectName, methodHash) {
if(!utils.common.getKeysFromHash(methodHash).length || !objectName) {
if (!utils.common.getKeysFromHash(methodHash).length || !objectName) {
return "";
}
var methodName = random.key(methodHash);
@ -22,20 +22,20 @@ utils.script = {
return objectName + "." + methodName + utils.script..methodHead(methodArgs);
},
setAttribute: function (objectName, attributeHash) {
if(!utils.common.getKeysFromHash(attributeHash).length || !objectName) {
if (!utils.common.getKeysFromHash(attributeHash).length || !objectName) {
return "";
}
var attributeName = random.key(attributeHash);
var attributeValue = random.pick(attributeHash[attributeName]);
var operator = " = ";
/*
if (typeof(attributeValue) == "number" && Random.chance(8)) {
operator = " " + Make.randomAssignmentOperator() + " ";
}
if (typeof(attributeValue) == "string") {
if (typeof(attributeValue) == "number" && Random.chance(8)) {
operator = " " + Make.randomAssignmentOperator() + " ";
}
if (typeof(attributeValue) == "string") {
attributeValue = "'" + attributeValue + "'";
}
*/
}
*/
return objectName + "." + attributeName + operator + attributeValue + ";";
},
makeConstraint: function (keys, values) {
@ -85,15 +85,18 @@ utils.script = {
return "(document.body || document.documentElement).appendChild" + utils.script..methodHead([name]);
},
forceGC: function () {
if (platform.isMozilla) {}
if (platform.isChrome) {
if (window.GCController)
return GCController.collect();
if (platform.isMozilla) {
}
if (platform.isChrome) {
if (window.GCController)
return GCController.collect();
}
if (platform.isSafari) {
}
if (platform.isIE) {
}
if (platform.isSafari) {}
if (platform.isIE) {}
},
getRandomElement: function() {
return "document.getElementsByTagName('*')[" + random.number(document.getElementsByTagName("*").length) + "]";
getRandomElement: function () {
return "document.getElementsByTagName('*')[" + random.number(document.getElementsByTagName("*").length) + "]";
}
};