1
0
mirror of https://gitlab.com/Deukhoofd/BattleSim.git synced 2025-09-02 00:47:19 +00:00
BattleSim/server/bw/rng.coffee
2016-02-01 23:19:30 +01:00

16 lines
398 B
CoffeeScript

class @FakeRNG
constructor: ->
next: (id) ->
Math.random()
# Returns a random integer N such that min <= N <= max.
randInt: (min, max, id) ->
Math.floor(@next(id) * (max + 1 - min) + min)
# Returns a random element in the array.
# Assumes the array is above length 0.
choice: (array, id) ->
index = @randInt(0, array.length - 1, id || "random choice")
array[index]