Probability Question : 2

Using Random5 function ( which returns a integer k $\in$ [1,5]  with probability $\frac{1}{5}$ ) , design Random7 function ( which returns a integer k $\in$ [1,7]  with probability $\frac{1}{7}$ ).

Advertisements

One Response to “Probability Question : 2”

1. connect2ppl Says:

Solution due to Krishna Chaitanya ( chaitanya518@gmail.com )

Random7 ( ) {
while ( 1 ) {
a = rand5()-1
b = rand5()-1
c = 5*a+b /* c is decimal equivalent of (ab) in BASE-5 notation */
if(c<21)
return c%7 + 1 /* this distributes integers from [0,20] into 7 buckets, 3 in each */
}
}