IMHO, this is an ambiguous, poorly worded question. I'll take a stab at what they're trying to ask and how I would answer it.
My interpretation of the question
Generate 5000 random integers from the set {1, 2, ..., 100} such that the probability mass function p(x) is proportional to (sin(x)+1).
Sketch of how I would answer the question
- Construct the probability mass function (essentially a vector)
- Use the vector (which defines the pmf) to generate draws from a categorical distribution (or multinomial distribution with n = 1).
Constructing this probability mass function is easy. I will use a vector to represent the function (i.e. f(1) is the first element of the vector, f(2) is the 2nd element of the vector etc...)
- Construct a vector x = 1,2,...,100
- Construct a new vector p_temp = sin(x) + 1
- Construct a new vector pm = p_temp / sum(p_temp) so that the probabilities sum to 1
Then pm(1) would be probability of drawing 1, pm(2) would be probability of drawing 2 etc... Once you have the pm vector, there are several ways to generate the random integers. Mathematically, you're drawing from a categorical distribution (could search for that). Python has functions for this, though it would also be easy to code your own.