Solution
-
Call rand6() twice and generate two numbers , let us call them and
- Generate the output number based on the below formula
Explanation of the above formula
If above formula is correct then probability of getting any number between 1-12 should be uniform i;e, p = 1/12.
Let's Estimate Probabilities
-
Case 1 : If num_2 is odd, then num_1 can be anything . In this case output number will be with
-
Case 2 : if num_2 is even, then num_1 can be anything . In this case output number will be with
import numpy as np
def rand6():
return np.random.randint(1, 6)
def rand12():
num = None
num = rand6() + (rand6()%2 ) *6
return num