Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I had a discussion with my friend about writing a function (a computer program) which generates 9 values randomly using a random number generator which generates 4 values, i.e I have a PRNG rand(4) {1,2,3,4} , I want to use that to write a PRNG rand(9) {1,2,3,4,5,6,7,8,9}.

My friend suggested that take three instances of rand(4),

where the first rand1(4) is mapped to 0, 9/4/, 9/2, (3/4)x9
the second instance rand2(4) is mapped to 1/4th of the above values
the third instance rand3(4) is mapped to 1/4th of the rand2(4) generator.

Finally, rand(9) is given by round( rand1(4)+rand2(4)+rand3(4) )

How accurate is this?, does the above method truly yield a uniform distribution ?(ignoring the fact that it is a PRNG)

share|improve this question
    
Note that this may be a bad idea unless the given PRNG is good enough. For example, to obtain uniform distribution for rand(9), your rand(4) must be uniform and independent ... –  Hagen von Eitzen Aug 27 '13 at 6:33
add comment

2 Answers

This doesn't precisely answer your question, but an alternative approach would be to use $(\mathrm{rand}(4)-1)+4(\mathrm{rand}(4)-1)+1$ and through out any values greater than $9$, which would give you a uniform distribution.

share|improve this answer
add comment

Your method essentially generates (assuming subsequent calls to rand(4) are independent) the number $\frac{9}{64}x$ with $x\in\{0,\ldots,63\}$ rounded (up? down?). Since there are $64>7\cdot 9$ equally likely values of $x$, the rounding will produce at least one value $\in\{0,\ldots,8\}$ for which there are at least $8$ values of $x$ producing it. So that outcome has a probability of at least $\frac18>\frac19$. A rejection startegy as proposed by Alex Becker can helkp you out of this.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.