Skip to content
Justice Tech School

Math and Random

Math has sqrt, sin, PI and more. rand and Random give random numbers.

Example
puts Math.sqrt(16), Math::PI.round(3), 10.gcd(4), 3.zero?
srand(1)
r = rand(1..6)
puts (1..6).cover?(r)
puts [1, 2, 3].shuffle(random: Random.new(1)).length

Result

4.0
3.142
2
false
true
3

Exercise

Square root.

Math.(16)

Quiz Test

What does rand(1..6) give?

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