JavaScript version
weightedRandom.js
const weightedRandom = (min, max) => ~~(Math.pow(Math.random(), 2) * (max - min)) + min;
TypeScript version
weightedRandom.ts
const weightedRandom = (min: number, max: number): number => ~~(Math.pow(Math.random(), 2) * (max - min)) + min;
Examples
examples.js
weightedRandom(2, 10); // 7
weightedRandom(2, 10); // 6
weightedRandom(2, 10); // 4
weightedRandom(2, 10); // 3
weightedRandom(2, 10); // 5