@tsports/go-colorful
Version:
A TypeScript port of the go-colorful package for working with colors
45 lines • 1.6 kB
TypeScript
/**
* Go-compatible random number generator implementation
*
* This module provides a way to generate identical random sequences to Go's math/rand
* package when compatibility is required. For normal use, the standard random functions
* should be preferred for performance reasons.
*/
import type { RandInterface as TSRandInterface } from './rand';
export interface GoRandInterface {
Float64(): number;
Intn(n: number): number;
}
/**
* Simple Linear Congruential Generator that approximates Go's behavior
* This is NOT a perfect implementation of Go's complex LFSR algorithm,
* but provides a deterministic sequence for testing purposes.
*/
export declare class GoCompatibleRand implements GoRandInterface, TSRandInterface {
private state;
constructor(seed?: number);
/**
* Generate a float64 in the range [0, 1)
* Uses a simple LCG algorithm for deterministic output
*/
float64(): number;
/**
* Generate an integer in the range [0, n)
*/
intn(n: number): number;
Float64(): number;
Intn(n: number): number;
}
/**
* Create a seeded random generator for deterministic palette generation.
* Use this when you need identical output to Go for testing or compatibility.
*
* @param seed The seed value (default: 1)
* @returns A RandInterface compatible with palette generation functions
*/
export declare function newSeededRand(seed?: number): GoRandInterface;
/**
* Default seed used by Go's math/rand when Seed(1) is called
*/
export declare const GO_DEFAULT_SEED = 1;
//# sourceMappingURL=go-compatible-rand.d.ts.map