Rich Newman

August 4, 2007

Random Numbers Problem

Filed under: general, Puzzles — richnewman @ 4:19 pm

Another problem doing the rounds relates to random numbers. Unlike my previous post, this one might make a (difficult) interview question:

Given a function that generates a integer random number between 1 and 5, write another function that generates an integer random number between 1 and 7.

Obviously you are intended to use the first function for the random element in your solution, not the Random class.

I have been unable to come up with an exact solution that takes finite time for this. I have written some C# code that either gives an exact solution but can theoretically take infinite time, or gives an inexact solution (although to any level of accuracy you like).

You can download my attempted solutions.

About these ads

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

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

The Shocking Blue Green Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 80 other followers

%d bloggers like this: