|
|
|
@ -143,8 +143,8 @@ function rad(x: LuaType): number {
|
|
|
|
function random(min?: LuaType, max?: LuaType): number {
|
|
|
|
function random(min?: LuaType, max?: LuaType): number {
|
|
|
|
if (min === undefined && max === undefined) return getRandom()
|
|
|
|
if (min === undefined && max === undefined) return getRandom()
|
|
|
|
const firstArg = coerceArgToNumber(min, 'random', 1)
|
|
|
|
const firstArg = coerceArgToNumber(min, 'random', 1)
|
|
|
|
const MIN = max === undefined ? firstArg : 1
|
|
|
|
const MIN = max === undefined ? 1 : firstArg
|
|
|
|
const MAX = max === undefined ? coerceArgToNumber(max, 'random', 2) : firstArg
|
|
|
|
const MAX = max === undefined ? firstArg : coerceArgToNumber(max, 'random', 2)
|
|
|
|
|
|
|
|
|
|
|
|
if (MIN > MAX) throw new Error("bad argument #2 to 'random' (interval is empty)")
|
|
|
|
if (MIN > MAX) throw new Error("bad argument #2 to 'random' (interval is empty)")
|
|
|
|
return Math.floor(getRandom() * (MAX - MIN + 1) + MIN)
|
|
|
|
return Math.floor(getRandom() * (MAX - MIN + 1) + MIN)
|
|
|
|
|