ixfx
    Preparing search index...

    Function chance

    • Chance of returning a or b, based on threshold p.

      p sets the threshold for picking b. The higher the value (up to 1), the more likely b will be picked.

      // 50% of the time it will return 100, 50% 110
      chance(0.5, 100, 110);
      // 90% of the time it will yield 110, 10% it will yield 100
      chance(0.9, 100, 110);

      Type Parameters

      • T

      Parameters

      • p: number | () => number

        Threshold to choose option B (value or function)

      • a: T | () => T

        Value or function for option A

      • b: T | () => T

        Value or function for option B

      • OptionalrandomSource: RandomSource

        Source of random numbers

      Returns T