Function weightedSource

Returns a random number, 0..1, weighted by a given easing function. Default easing is quadIn, which skews towards zero. Use weighted to get a value directly.

import * as Random from 'https://unpkg.com/ixfx/dist/random.js';
const r1 = Random.weightedSource(); // quadIn easing by default, which skews toward low values
r1(); // Produce a value

const r2 = Random.weightedSource(`quadOut`); // quadOut favours high values
r2(); // Produce a value

weighted Returns value instead of function

  • Parameters

    • easingNameOrOptions:
          | "bounceOut"
          | "quintIn"
          | "quintOut"
          | "arch"
          | "smoothstep"
          | "smootherstep"
          | "sineIn"
          | "sineOut"
          | "quadIn"
          | "quadOut"
          | "sineInOut"
          | "quadInOut"
          | "cubicIn"
          | "cubicOut"
          | "quartIn"
          | "quartOut"
          | "expoIn"
          | "expoOut"
          | "quintInOut"
          | "expoInOut"
          | "circIn"
          | "circOut"
          | "backIn"
          | "backOut"
          | "circInOut"
          | "backInOut"
          | "elasticIn"
          | "elasticOut"
          | "bounceIn"
          | "bell"
          | "elasticInOut"
          | "bounceInOut"
          | Readonly<{
              easing?:
                  | "bounceOut"
                  | "quintIn"
                  | "quintOut"
                  | "arch"
                  | "smoothstep"
                  | "smootherstep"
                  | "sineIn"
                  | "sineOut"
                  | "quadIn"
                  | "quadOut"
                  | "sineInOut"
                  | "quadInOut"
                  | "cubicIn"
                  | "cubicOut"
                  | "quartIn"
                  | "quartOut"
                  | "expoIn"
                  | "expoOut"
                  | "quintInOut"
                  | "expoInOut"
                  | "circIn"
                  | "circOut"
                  | "backIn"
                  | "backOut"
                  | "circInOut"
                  | "backInOut"
                  | "elasticIn"
                  | "elasticOut"
                  | "bounceIn"
                  | "bell"
                  | "elasticInOut"
                  | "bounceInOut";
              source?: RandomSource;
          }> = ...

      Easing name or options quadIn by default.

    Returns RandomSource

    Function which returns a weighted random value