Skip to content

Instantly share code, notes, and snippets.

View Tvde1's full-sized avatar
:bowtie:

Tim van den Essen Tvde1

:bowtie:
  • Wolfpack IT
  • Eindhoven
  • X @Tvde1
View GitHub Profile
@Tvde1
Tvde1 / WeightedValueChooser.ts
Last active April 30, 2021 20:03
Random weighted value TypeScript
// -----------------
// Usage
// Expected: value one is four times as likely to be chosen than value three.
// And, value two is two times less likely to be chosen than value one.
const options = [
new WeightedValue('Value one', 4),
new WeightedValue('Value two', 2),
new WeightedValue('Value three', 1)