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 */
    }
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: