export function getRandomGaussian(mean: number, stdDev: number) {
    let u1 = Math.random();
    let u2 = Math.random();
    let z0 = Math.sqrt(-2.0 * Math.log(u1)) * Math.cos(2.0 * Math.PI * u2);
    return z0 * stdDev + mean;
}

export function getRandomInRange(min: number, max: number) {
    const mean = 0;
    const stdDev = 3000;
    let randomNum;

    do {
        randomNum = getRandomGaussian(mean, stdDev);
    } while(randomNum < min || randomNum > max);

    return Math.round(randomNum);
}

export function weightedRandom(weight: number) {
    if (weight < 1 || weight > 100_000) {
        throw new Error("Weight must be between 1 and 100000.");
    }

    return 1 / (1 + Math.exp(-0.00005 * (weight - 40_000))) * 0.7 + Math.random() * 0.3;
}