Inverse transform sampling implementation using a random generator and a list of numbers

51 Views Asked by At

I have to implement a function in a programming language (Scheme) that do the following.

Given a list of pairs, element and a number, it will return the element. The number on each pair is the probability to return the element in its pair. E.g., if I have the following list (a 1), (b 2), (c 3), and if I run that function 6,000 times, I will get the following results:

a -  998 times
b - 2003 times
c - 2999 times

The probability to get a is 1/6, b is 2/6 and c is 3/6.

The programming language has a function, named random, that returns real numbers between 0 and 1. To implement this function I have to use that random function and the Inverse transform sampling, but I don't know how.

By the way, the list of pairs can change on each call to that function.

What do I have to do to implement that function using Inverse transform sampling?