Random Number Generator with weighted range

I’d like to generate a random number between min and max limits, but with a weighted probability applicated to the range the number is in.

For instance:

const ranges = [
    {
        min: 0,
        max: 19,
        weight: 0.5, // 50% probability
    },
    {
        min: 20,
        max: 49,
        weight: 0.25, // 25%
    },
    {
        min: 50,
        max: 74,
        weight: 0.17, // 15%
    },
    {
        min: 75,
        max: 89,
        weight: 0.08, // 8%
    },
    {
        min: 90,
        max: 100,
        weight: 0.02, // 2%
    },
];

In my mind, I’d like to pick one of my range according to its weight, then pick a random number in between the selected range, as each number in a set range have the same probability to get picked.

I can’t find a good way to pick one range based on its weight.