/ proof-of-concept / audio-spike-sorting
Sign in
proof-of-concept / audio-spike-sorting
audio-spike-sorting / src / bench / rng.ts
23 lines · 684 BCodeBlameHistory
21abc12audio-spike-sorting: benchmark framework for audio event detection and classificationJeremy Magland 1/** Seeded RNG (mulberry32) so every synthesized dataset is reproducible
2 * from (base seed, run index) alone. */
3export type Rng = () => number;
5export function mulberry32(seed: number): Rng {
6 let a = seed >>> 0;
7 return () => {
8 a |= 0;
9 a = (a + 0x6d2b79f5) | 0;
10 let t = Math.imul(a ^ (a >>> 15), 1 | a);
11 t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
12 return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
13 };
16/** Fisher-Yates shuffle in place. */
17export function shuffle<T>(arr: T[], rng: Rng): T[] {
18 for (let i = arr.length - 1; i > 0; i--) {
19 const j = Math.floor(rng() * (i + 1));
20 const t = arr[i]; arr[i] = arr[j]; arr[j] = t;
21 }
22 return arr;
↑↓ move↵openescclose