mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-08-30 02:24:42 +08:00
update: character allocation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
export type RNG = (max?: number, min?: number) => number
|
||||
export function random(max: number = 1, min: number = 0, rng?: RNG): number {
|
||||
if (rng) return rng(max, min)
|
||||
if (max < min) [max, min] = [min, max]
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min
|
||||
}
|
||||
export function pick<T>(items: T[], rng?: RNG) {
|
||||
@@ -58,3 +59,11 @@ export function format(str: string, getValueFn: GetValueFn): string {
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export function zoneFit(value: number, zone: [number, number]) {
|
||||
const max = Math.max(zone[0], zone[1])
|
||||
if (value > max) return max
|
||||
const min = Math.min(zone[0], zone[1])
|
||||
if (value < min) return min
|
||||
return value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user