| ||
|
A part of techInterview.org: answers to technical interview questions.
Your host: Michael Pryor |
Given a function rand5() which can generate numbers 1-5 with a euqal probability, how to generate number 1-7 with equal probability using rand5()?
Call rand5 two times and then you get a number between 0 to 24.. Divide the spectrum evenly as...0-2 : 1; 3-5 : 2, ...,18-20 : 7...for the rest of the values 21,22,23,34 repeat this procedure...i think this will give you a random distribution Saturday, July 10, 2010
Hi jdk, how do you do this? Use rand5 twice, then you have a number n from 1 to 25 equally likely? Saturday, July 10, 2010 | |
Powered by FogBugz
