Prev: Customized GUINext: bsearch.rb From: Alex Untitled on 14 Nov 2009 21:54 I want to create a program that asks you to guess a number between two numbers. The problem is that I can't figure out how to make the numbers that you're guessing between random and have the random number you are guessing between those two numbers. Does anybody know how to do this? -- Posted via http://www.ruby-forum.com/. From: Marnen Laibow-Koser on 14 Nov 2009 22:00 Alex Untitled wrote:> I want to create a program that asks you to guess a number between two > numbers. The problem is that I can't figure out how to make the numbers > that you're guessing between random and have the random number you are > guessing between those two numbers. Does anybody know how to do this? Well, you know how to generate the first two random numbers, right? Just take the difference between those two as the range in which to generate the third. Simple. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen(a)marnen.org -- Posted via http://www.ruby-forum.com/. From: Alex Untitled on 14 Nov 2009 22:03 Marnen Laibow-Koser wrote:> Alex Untitled wrote: >> I want to create a program that asks you to guess a number between two >> numbers. The problem is that I can't figure out how to make the numbers >> that you're guessing between random and have the random number you are >> guessing between those two numbers. Does anybody know how to do this? > > Well, you know how to generate the first two random numbers, right? > Just take the difference between those two as the range in which to > generate the third. Simple. > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen(a)marnen.org So, would it be something like this? num1 = rand(101) num2 = rand(101) num3 = num1 + num2 Anyway, thank you! -- Posted via http://www.ruby-forum.com/. From: Tony Arcieri on 14 Nov 2009 22:08 [Note: parts of this message were removed to make it a legal post.] On Sat, Nov 14, 2009 at 7:54 PM, Alex Untitled wrote: > I want to create a program that asks you to guess a number between two > numbers. The problem is that I can't figure out how to make the numbers > that you're guessing between random and have the random number you are > guessing between those two numbers. Does anybody know how to do this? > first + rand(last + 1 - first) -- Tony Arcieri Medioh/Nagravision From: Alex Untitled on 14 Nov 2009 22:09 OK, that didn't work. That just added the two numbers. How do I make a number between two numbers again? I can't seem to find it. -- Posted via http://www.ruby-forum.com/.  |  Next  |  Last Pages: 1 2 3 Prev: Customized GUINext: bsearch.rb