Name: Anonymous 2012-02-01 5:14
You are given a function randBit() that returns {0,1}
You want to write a function randNum(start,stop) {a,b} where the function will return a number between a and b with even distribution.
The function is required to run in a guaranteed time, so you can't just use binary representation. ex) you want a number between 0 and 10, the closest bit combination is 16, so a bin representation will fail 6 out 16 times. What is the best way to do this?
You want to write a function randNum(start,stop) {a,b} where the function will return a number between a and b with even distribution.
The function is required to run in a guaranteed time, so you can't just use binary representation. ex) you want a number between 0 and 10, the closest bit combination is 16, so a bin representation will fail 6 out 16 times. What is the best way to do this?