Deaf Calculus

L

Luke Kyrchner

Luke Kyrchner wrote:
Okay, I just figured one thing out:
Instead of putting .capitalize, you put .upcase
What I would like to know is how to put in a random sentence, like you
make 7 different sentences, how could you make the program put a
sentence at random instead of a date?


Attachments:
http://www.ruby-forum.com/attachment/3782/Calculus.rb
 
T

Todd Benson

Luke Kyrchner wrote:
Okay, I just figured one thing out:
Instead of putting .capitalize, you put .upcase
What I would like to know is how to put in a random sentence, like you
make 7 different sentences, how could you make the program put a
sentence at random instead of a date?

Just a hint.

'daygs' used for "Snatch" reference :)...

array = ["Ya like daygs?", "Do I like daygs?", "Yeah, d'ya like
daygs", "Oh, 'do I like dahgs.'", "Yeah, I like dahgs."]
puts array[rand(array.size - 1)]

Todd
 
B

Brian Candler

Todd said:
array = ["Ya like daygs?", "Do I like daygs?", "Yeah, d'ya like
daygs", "Oh, 'do I like dahgs.'", "Yeah, I like dahgs."]
puts array[rand(array.size - 1)]

I think you want puts array[rand(array.size)], otherwise the last
element won't ever be used.

------------------------------------------------------------ Kernel#rand
rand(max=0) => number
------------------------------------------------------------------------
Converts _max_ to an integer using max1 = max+.to_i.abs+. If the
result is zero, returns a pseudorandom floating point number
greater than or equal to 0.0 and less than 1.0. Otherwise, returns
a pseudorandom integer greater than or equal to zero and less than
max1.
 
T

Todd Benson

Todd said:
array = ["Ya like daygs?", "Do I like daygs?", "Yeah, d'ya like
daygs", "Oh, 'do I like dahgs.'", "Yeah, I like dahgs."]
puts array[rand(array.size - 1)]

I think you want puts array[rand(array.size)], otherwise the last
element won't ever be used.

Yes, yes; must read the docs before responding :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top