VocabReminder
Easily build a great vocabulary without studying! Now on the App Store!
Click here for more info about the app

Ruby Rand Range

       

I assumed that rand would take a range as an argument. Something like rand(10..20), generating a random number between 10 and 20. Seems like you'd do this fairly often when working with random numbers and therefore, included. However, it doesn't work. But the solution is almost as easy.


10 + rand(11) #=> produces a random number between 10 and 20

Since rand starts at 0 (like array indexes), we need to add an extra 1 to get what we're expecting.

Tagged w/ #numbers #one #rand #ruby #simple #zeroruby