def getRandomNumbers(count, min, max)
array = []
while array.length < count
tmp = rand(max) + min
if array.include?(tmp)
next
else
array.push(tmp)
end
end
return array
end
def prettyPrint(someArray)
string = ""
someArray.each do |item|
string += item.to_s + "\t"
end
puts string
end
array = getRandomNumbers(6, 1, 49)
prettyPrint(array)
I'm just learning Ruby and wrote this little two functions just to play around and get a feel for Ruby syntax etc. I wanted a function that generates a given amount of random numbers within certain limits. In this example for 6 lottery numbers, therefore each number should only occur once. The second method is pretty self explanatory.
The code runs and does what he is supposed to do. However, what are nice tweaks and tricks to make this code nicer and utilizing the abilities of Ruby?