All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
More randomness! (Posted on 2003-06-30) Difficulty: 3 of 5
Suppose you have a function (or a magic ball) that is capable of producing a totally random integer between 1 and 5 (inclusive).

Using this, how would you generate a random number (also an integer) between 1 and 7 (inclusive)? (Note that the for the number to be random, all integers between 1 and 7 must have an equal chance of being generated)

Assume that using your 1-5 generator is pretty time-consuming, so you want to minimize the number of times you are going to use it.

See The Solution Submitted by levik    
Rating: 4.3333 (6 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re(2): solution | Comment 10 of 16 |
(In reply to re: solution by Gamer)

My assumption was that this random number generator (of integers between 1 and 7) would be called several times, not just once. I see that that's not stated in the problem, but I guess I just didn't (don't) see a need for just one random number, but rather some stochastic trials that need integers from 1 - 7.

But yes, if you need only one random number, choosing just two integers from 1-5 and using fl's techniques would be superior.
  Posted by Charlie on 2003-06-30 15:14:41

Please log in:
Remember me:
Sign up! | Forgot password

Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (2)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Copyright © 2002 - 2019 by Animus Pactum Consulting. All rights reserved. Privacy Information