1
0

rand.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. setup.qsp_rand = function (min, max) {
  2. min = Math.ceil(min);
  3. max = Math.floor(max) + 1;
  4. let randomNumber;
  5. if(State.temporary.randFunctionOverwrite && State.temporary.randFunctionOverwrite.length > 0){
  6. randomNumber = State.temporary.randFunctionOverwrite.last()();
  7. }
  8. else{
  9. if(!State.variables.randomNumbers){
  10. State.variables.randomNumbers = [];
  11. }
  12. while(State.variables.randomNumbers.length < 50)
  13. State.variables.randomNumbers.push(Math.random());
  14. randomNumber = State.variables.randomNumbers.shift();
  15. }
  16. //return Math.floor(State.variables.randomNumbers.shift() * (max - min) + min); // The maximum is inclusive and the minimum is inclusive
  17. return Math.floor(randomNumber * (max - min) + min); // The maximum is inclusive and the minimum is inclusive
  18. }
  19. setup.cyrb128 = function (str) {
  20. let h1 = 1779033703, h2 = 3144134277,
  21. h3 = 1013904242, h4 = 2773480762;
  22. for (let i = 0, k; i < str.length; i++) {
  23. k = str.charCodeAt(i);
  24. h1 = h2 ^ Math.imul(h1 ^ k, 597399067);
  25. h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);
  26. h3 = h4 ^ Math.imul(h3 ^ k, 951274213);
  27. h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);
  28. }
  29. h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);
  30. h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);
  31. h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);
  32. h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);
  33. return [(h1^h2^h3^h4)>>>0, (h2^h1)>>>0, (h3^h1)>>>0, (h4^h1)>>>0];
  34. }
  35. setup.mulberry32 = function(a) {
  36. return function() {
  37. var t = a += 0x6D2B79F5;
  38. t = Math.imul(t ^ t >>> 15, t | 1);
  39. t ^= t + Math.imul(t ^ t >>> 7, t | 61);
  40. return ((t ^ t >>> 14) >>> 0) / 4294967296;
  41. }
  42. }