npm install @pqt/weighted-random
# OR
yarn add @pqt/weighted-random
import { weightedRandom, Items } from "@pqt/weighted-random";
const items: Items = [
["Audi", 3],
["BMW", 1],
["Ferrari", 7],
["Lamborghini", 7],
["RAM", 4],
["Tesla", 6]
];
weightedRandom(items); // => "Lamborghini" (OR any of the other options with a variability based on weight)
import { weightedRandom } from "@pqt/weighted-random";
weightedRandom([
["Audi", 3],
["BMW", 1],
["Ferrari", 7],
["Lamborghini", 7],
["RAM", 4],
["Tesla", 6]
]); // => "Lamborghini" (OR any of the other options with a variability based on weight)
MIT