diff --git a/src/js/utilJS.tw b/src/js/utilJS.tw index 69f48616013d7dd83bcbe70269b23ae070a764f0..60e1b6694f38a4d2edd7df6b8df536cf04a730f2 100644 --- a/src/js/utilJS.tw +++ b/src/js/utilJS.tw @@ -400,6 +400,26 @@ window.numberWithCommas = function(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } + +window.jsRandom = function(min,max) { + return Math.floor(Math.random()*(max-min+1)+min); +} + +window.jsRandomMany = function (arr, count) { + var result = []; + var _tmp = arr.slice(); + for (var i = 0; i < count; i++) { + var index = Math.ceil(Math.random() * 10) % _tmp.length; + result.push(_tmp.splice(index, 1)[0]); + } + return result; +} + +window.jsEither = function(choices) { + var index = Math.floor(Math.random() * choices.length); + return choices[index]; +} + /* Make everything waiting for this execute. Usage: