Tsallaka zuwa abun ciki
Justice Tech School

Random and Time

rand and Random give random numbers, and Time handles dates. Use strftime to format and Time.at for epoch values.

Example
srand(1)
puts rand(1..6).between?(1, 6)
t = Time.utc(2026, 3, 15, 9, 30)
puts t.strftime("%d %B %Y %H:%M")
puts t.year, t.wday, (t + 86400).day

Result

true
15 March 2026 09:30
2026
0
16

Exercise

Random die roll.

(1..6)

Quiz Test

Which formats a time?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.