Search code examples
pythonmontecarlo

How can I transform numbers in a range of 0-1 to a 1-52 range using Discrete Uniform Distribution in Python?


What I am looking for is for a method in Python or any other way to solve this, for what I know there is one method, but I couldn't find it, in context what I am doing is calculate the probability of a pair, two pairs etc to appear in a poker play using Montecarlo method, at the moment I'm using the random.sample function to do that, but I want to use my own methods to generate random numbers that return numbers between 0-1, and I want to use Discrete Uniform Distribution in order to be sure that every number has the same probability to appear.

I apreciate any help you can give.


Solution

  • This is a math question more than python. here is the soln:

    Code:

    import random
    
    arr_0_1 = [random.random() for i in range(10)]
    print(arr_0_1)
    d = 1/51
    arr_1_52 = [n/d + 1  for n in arr_0_1]
    print(arr_1_52)
    

    Output:

    [0.49864143060719257, 0.9124661869543931, 0.14064674065024652, 0.6162308610305717, 0.698038549502753, 0.18002207940954196, 0.7337352732415695, 0.34955525833304546, 0.6380173638897209, 0.14733996159513485]
    [26.430712960966822, 47.535775534674045, 8.172983773162573, 32.42777391255916, 36.5999660246404, 10.18112604988664, 38.42049893532005, 18.82731817498532, 33.53888555837577, 8.514338041351877]