Skip to content

Files

Latest commit

 

History

History
31 lines (23 loc) · 742 Bytes

Style-RandomWithOffset.md

File metadata and controls

31 lines (23 loc) · 742 Bytes

Pattern: Use of random number with offset

Issue: -

Description

This rule checks for the use of randomly generated numbers, added/subtracted with integer literals, as well as those with Integer#succ and Integer#pred methods. Prefer using ranges instead as it clearly states the intentions.

Examples

# bad
rand(6) + 1
1 + rand(6)
rand(6) - 1
1 - rand(6)
rand(6).succ
rand(6).pred
Random.rand(6) + 1
Kernel.rand(6) + 1
rand(0..5) + 1

# good
rand(1..6)
rand(1...7)

Further Reading