Files
coins/src/components/hail/utils.ts
T
luis 37ff3dc924
Build and Deploy / build-deploy (push) Successful in 28s
Reimplemented (but better)
2026-06-12 16:29:28 +01:00

16 lines
424 B
TypeScript

import type { PieceWithIssuer } from '@/db/types';
export function rand(min: number, max: number): number {
return min + Math.random() * (max - min);
}
export function pickCoin(pool: PieceWithIssuer[]): PieceWithIssuer {
const total = pool.reduce((sum, c) => sum + c.count, 0);
let r = Math.random() * total;
for (const c of pool) {
r -= c.count;
if (r < 0) return c;
}
return pool[pool.length - 1];
}