X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=utils%2Falea.js;h=751d3474b42a5fd6bebaefddb0fbf49d8a719e98;hb=HEAD;hp=aa3aa57cec2bce2fab1b910e845f9402b245c0b1;hpb=bc2bc396ec4df092f218b58a0fbf08ba7eb8ca6e;p=xogo.git diff --git a/utils/alea.js b/utils/alea.js index aa3aa57..d892824 100644 --- a/utils/alea.js +++ b/utils/alea.js @@ -22,10 +22,14 @@ export const Random = { min = 0; } if (!Random.rand) - Random.setSeed(Math.floor(Math.random() * 1984)); + Random.setSeed(Math.floor(Math.random() * 19840)); return Math.floor(Random.rand() * (max - min)) + min; }, + randBool: function() { + return Random.randInt(0, 2) == 0; + }, + // Inspired by https://github.com/jashkenas/underscore sample: function(arr, n) { n = n || 1; @@ -34,7 +38,8 @@ export const Random = { const rand = Random.randInt(index, arr.length); [ cpArr[index], cpArr[rand] ] = [ cpArr[rand], cpArr[index] ]; } - return cpArr.slice(0, n); + const res = cpArr.slice(0, n); + return (n >= 2 ? res : res[0]); }, shuffle: function(arr) {