I decided that I wanted to learn Ruby, but I’m not much of a reader. Far too impatient, so I figured I’d jump into some code and write something. The result was a random number generator. It’s not great, but it does the job. Pick a minimum and maximum number, and it will generate them.
#Random number generator script.another = "y"
while another[/^y/] == "y" or another[/^Y/] == "Y"
#Request the minimum
print "Enter minimum number: ";
min = readline();
print "Enter maximum number: ";
max = readline();
if min.to_i() > max.to_i()
# Max is greater than Min, switch them.
temp = min;
min = max;
max = temp;
end
#calculate the base number.
# E.g: 3 - 7 yields
#a possible return of 5 numbers. 3, 4, 5, 6, and 7
base = max.to_i() - min.to_i() + 1;
#Seed the random number generator.
srand(Time.now.to_i());
print rand(base)+min.to_i();
print "\nDo another? :"
another = readline();
end