diff options
Diffstat (limited to 'client/lib')
| -rw-r--r-- | client/lib/util.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/client/lib/util.js b/client/lib/util.js index c6df6ec..7bca506 100644 --- a/client/lib/util.js +++ b/client/lib/util.js @@ -12,9 +12,11 @@ document.body.classList.add(isMobile ? 'mobile' : 'desktop') const browser = { isIphone, isIpad, isMobile, isDesktop } function clamp(n,a,b){ return n<a?a:n<b?n:b } -function choice (a){ return a[ Math.floor(Math.random() * a.length) ] } +function choice (a){ return a[ randint(a.length) ] } function mod(n,m){ return n-(m * Math.floor(n/m)) } function firstTouch(f){ return e => { e.preventDefault(); f(e.touches[0]) }} +function randint(n){ return Math.floor(Math.random() * n) } +function randrange(a,b) { return Math.random() * (b-a) + a } function requestAudioContext (fn) { if (isMobile) { @@ -59,5 +61,10 @@ function requestAudioContext (fn) { } } -export { choice, mod, clamp, browser, firstTouch, requestAudioContext } +export { + choice, + randint, randrange, + mod, clamp, + browser, firstTouch, requestAudioContext +} |
