aura-glass
Version:
A comprehensive glassmorphism design system for React applications with 142+ production-ready components
52 lines (50 loc) • 1.35 kB
JavaScript
/**
* Simple deterministic pseudo-random number generator for SSR consistency.
*/
class SeededRandom {
constructor(seed = Date.now()) {
this.state = SeededRandom.normalizeSeed(seed);
}
static normalizeSeed(seed) {
if (typeof seed === 'number' && Number.isFinite(seed)) {
return SeededRandom.hash(seed);
}
if (typeof seed === 'string') {
let hash = 0;
for (let i = 0; i < seed.length; i++) {
hash = (hash << 5) - hash + seed.charCodeAt(i);
hash |= 0; // Convert to 32-bit integer
}
return SeededRandom.hash(hash);
}
return SeededRandom.hash(Date.now());
}
static hash(input) {
let x = input | 0;
x ^= x >>> 16;
x = Math.imul(x, 0x7feb352d);
x ^= x >>> 15;
x = Math.imul(x, 0x846ca68b);
x ^= x >>> 16;
return x >>> 0;
}
next() {
// LCG parameters from Numerical Recipes
this.state = 1664525 * this.state + 1013904223 >>> 0;
return this.state / 0xffffffff;
}
nextInRange(min, max) {
return min + (max - min) * this.next();
}
nextInt(min, max) {
return Math.floor(this.nextInRange(min, max + 1));
}
nextSigned() {
return this.next() * 2 - 1;
}
}
const createSeededRandom = seed => {
return new SeededRandom(seed);
};
export { SeededRandom, createSeededRandom };
//# sourceMappingURL=random.js.map