Function isHit

  • EN: Hit probability (1% ~ 100%).

    ZH: 百分位概率。

    Usage:

    const ret = isHit(0.5); // 0.01 ~ 1 true/false
    console.log(ret);

    Output:

    true
    

    Example: Test the precision.

    // Test
    let trueCount = 0;
    let falseCount = 0;
    new Array(1000000).fill(0).forEach(() => {
    if (isHit(0.5)) {
    trueCount++;
    } else {
    falseCount++;
    }
    });
    console.log(trueCount, falseCount); // 499994 500006

    Parameters

    • rate: number

      0.1 ~ 1 => 1% ~ 100%

    Returns boolean

    true 命中