Skip to content

random-bound-one

Detect random integer calls whose upper bound permits only zero.

Updated View as Markdown

Default severity: warning

Bounded random integer functions generate values in the half-open range from zero up to, but excluding, the bound. A bound of one therefore always returns zero.

Bad

choice := rand.Intn(1)

Good

choice := rand.Intn(2)

The check covers package functions and Rand methods in both standard random packages.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close