SQLTerminal.app
now available

XPath.app
now available
Want fresh tech tips in your inbox?

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

Apps I've Built

XPath Expression Editor
Practice and improve your XPath skills with XPath Editor
Click to buy on the App Store
Photo Location Changer
Easily change the location on your photos and videos
Click here for more info about the app
Photo Date Changer
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app