Fix #8506: randi -> rand(1:n)

Backport of 3e5ab09