Can random(5) output the number 5?

Yes but in many ways processing obscures what is going on and leads to muddled thinking. Far better in ruby:-

rand # yields values in range 0..1.0
rand(0..6) # yields ints in inclusive range
rand(0...6) # yields ints in exclusive range
rand(200..255) #  yields ints in inclusive range

Concise syntax but there’s more, say you want a random selection from an array in ruby then just sample it

[0, 100, 34, 78].sample

But of course ruby is a bit more crazy/weird because your array can be a bag of all sorts.

1 Like