Commit e9411254 by Ivan Kubota

Math.random.seeded.setSeed now can accept strings

Math.random.seeded.rand — random from Array items or between two values Math.random.seeded.constructor now returns a constructor that can create an independent seeded random instance Ajax. small fix. Bug in Setting Headers
parent e3776108
......@@ -4,7 +4,7 @@
if(obj[k] === void 0 || obj[k] === null)
delete obj[k];
}
return obj[k];
return obj;
};
const transformCfg = function( cfg ){
return Object.assign( {}, cfg, {
......
function mulberry32(a) {
var out = function() {
var imul = Math.imul, floor = Math.floor;
var out = random = function() {
var t = a += 0x6D2B79F5;
t = Math.imul(t ^ t >>> 15, t | 1);
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
t = imul(t ^ t >>> 15, t | 1);
t ^= t + imul(t ^ t >>> 7, t | 61);
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
......@@ -10,7 +11,17 @@ function mulberry32(a) {
return a;
};
out.setSeed = function(A) {
a = A;
if(typeof A === 'string'){
a = 13;
A.split('').reduce(function(accum, char){
var t = a += 0x6D2B79F5 + accum + char.charCodeAt(0);
t = imul(t ^ t >>> 15, t | 1);
t ^= t + imul(t ^ t >>> 7, t | 61);
return ((t ^ t >>> 14) >>> 0) / 4294967296;
}, 666);
} else {
a = A;
}
};
out.setStringSeed = function(str) {
str = str.replace(/[^0-9a-z]/g,'').substr(0,12);
......@@ -20,6 +31,22 @@ function mulberry32(a) {
out.getStringSeed = function() {
return a.toString(36);
};
out.rand = function(a, b){
if(Array.isArray(a)){
return a[out()*a.length|0];
}
var r = out();
if(b === void 0)
return floor(r*a);
return floor(r*(b-a+1)+a);
};
Object.assign(out.rand, out);
delete out.rand.rand;
out.constructor = mulberry32;
return out;
}
......
{
"name": "react-vanilla",
"version": "1.1.19",
"version": "1.1.21",
"description": "",
"main": "DOM.js",
"scripts": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment