JSSM, a JavaScript state machine - the FSM for FSL
    Preparing search index...

    Function weighted_sample_select


    • Draws n weighted random samples from an array of objects. Each draw is independent (with replacement), delegating to weighted_rand_select.

      const opts = [
      { value: 'a', probability: 0.9 },
      { value: 'b', probability: 0.1 }
      ];

      weighted_sample_select(3, opts, 'probability');
      // e.g. [ { value: 'a', ... }, { value: 'a', ... }, { value: 'b', ... } ]

      Parameters

      • n: number

        Number of samples to draw.

      • options: any[]

        Non-empty array of weighted objects.

      • probability_property: string

        Name of the numeric weight property.

      • Optionalrng: JssmRng

        Optional random number generator.

      Returns any[]

      An array of n independently selected items.