From: Josh Cheek Date: 2009-11-16T17:08:12+09:00 Subject: Re: How do I get a random number between two random numbers? --000e0cd50a2a85f2300478788238 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Nov 16, 2009 at 1:45 AM, Steve Wilhelm wrote: > Josh Cheek wrote: > > > > > # How about something like: > > > > max = 100 > > > > low , high = [ rand(max) , rand(max) ].sort > > > > difference = high - low > > > > middle = low + rand(difference).to_i #to_i for if low and high have > > same > > value > > > > puts "low = #{low}" > > puts "middle = #{middle}" > > puts "high = #{high}" > > The problem with your solution is that low and high can be the same > number. > -- > Posted via http://www.ruby-forum.com/. > > In that case, the cardinality of the solution set is 1, perhaps not desirable for a guessing game, but it is not stated that this should not happen, and if no minimum range is specified, then it is subjective where that line is drawn. ie if a solution set with cardinality 1 is not appropriate, then what about a solution set with cardinality two? At what point do we say the numbers are sufficiently far apart that they are acceptable? Perhaps a different approach is required altogether. Instead of giving the maximum value the numbers can be, give the minimum and maximum difference between the numbers. I don't see much value in a minimum number anyway, choosing a random number between 90 and 100 doesn't seem to offer anything over choosing a minimum number between 0 and 10. While I think saying "give me an upper bound between 10 and 20, with a target between 0 and that number" is a better approach, it is not what was asked for, and I thought it would be better to answer the question as asked, than to impose my own restrictions. --000e0cd50a2a85f2300478788238--