Languages
[Edit]
EN

TypeScript - random values from array with probability (different probability per item)

0 points
Created by:
Bess
571

In this short article, we would like to show how in TypeScript, get random items from an array using different randomization probabilities per item.

Practical example

Edit

The main idea used in the below example to randomize items with different probabilities is to create an array that represents items distribution - items are repeated many times to affect randomization.

Example output:

Alternative titles

  1. TypeScript - random values from array with probability distribution
  2. TypeScript - random values from array with custom weight
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join