SPB Git

spb/llmindex Public

The discriminative, contamination-resistant, fully transparent LLM ranking — updated live.

TypeScript 77.9% TeX 15.2% Python 3.7% SQL 1.4% JavaScript 1.1% Shell 0.5%
1.6 KB · 57 lines typescript
Raw Blame History
1/**2 * llmindex.io — deterministic seeded RNG for item generation/perturbation3 * Author:  Simon-Pierre Boucher4 * Contact: contact@spboucher.ai5 * License: Proprietary — © Simon-Pierre Boucher, all rights reserved6 */78/** FNV-1a 32-bit hash of a string seed. */9export function hashSeed(seed: string): number {10  let h = 0x811c9dc5;11  for (let i = 0; i < seed.length; i++) {12    h ^= seed.charCodeAt(i);13    h = Math.imul(h, 0x01000193);14  }15  return h >>> 0;16}1718export interface Rng {19  /** Uniform float in [0,1). */20  next(): number;21  /** Uniform integer in [min,max] inclusive. */22  int(min: number, max: number): number;23  /** Pick one element. */24  pick<T>(arr: readonly T[]): T;25  /** Fisher-Yates shuffle (copy). */26  shuffle<T>(arr: readonly T[]): T[];27}2829/** mulberry32 PRNG — fast, deterministic, good enough for item perturbation. */30export function createRng(seed: string): Rng {31  let a = hashSeed(seed);32  const next = (): number => {33    a |= 0;34    a = (a + 0x6d2b79f5) | 0;35    let t = Math.imul(a ^ (a >>> 15), 1 | a);36    t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;37    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;38  };39  return {40    next,41    int: (min, max) => min + Math.floor(next() * (max - min + 1)),42    pick: (arr) => {43      const el = arr[Math.floor(next() * arr.length)];44      if (el === undefined) throw new Error('pick from empty array');45      return el;46    },47    shuffle: (arr) => {48      const out = [...arr];49      for (let i = out.length - 1; i > 0; i--) {50        const j = Math.floor(next() * (i + 1));51        [out[i], out[j]] = [out[j]!, out[i]!];52      }53      return out;54    },55  };56}57