I am trying to get a random year between 1900 and 1980 with Ruby.
So far I have:
puts 'the year was: ' + 1900.to_s + rand(1980).to_s
Give this a try
(1900 + rand(81)).to_s
To be clear for passersby
First, there was an issue regarding string concatenation. The original code in the question was concatenating two strings (containing numbers) together. Example:
"1900" + "1920" = "19001920"
Second, there was an issue the range of random numbers being generated. In this case, since we only want a range of 80 years, we want to use rand(81), instead of rand(1980). We then take that result and add it to the base number, which will give us a random number between 1900 and 1980.