update: character allocation

This commit is contained in:
Vick Scarlet
2026-08-16 20:06:16 +08:00
committed by 神戸小鳥
parent f4204601ee
commit a0e3f1b355
10 changed files with 149 additions and 81 deletions
+9
View File
@@ -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
}