Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Stupid randint. I have to look it up every time. And I have to look up numpy's randint as well.


randrange is the fixed randint, which works just as you'd expect. It's far preferable to randint, for the aforementioned reason, and ever since I started using it all those annoying off by one errors that randint kept giving me vanished.

The one thing I still use randint for is rolling dice. randint(1,6) is the equivalent of a six-sided die, and is that bit more readable as such than the equivalent using randrange.

But for any other purpose, randrange beats randint hands down. Off-by-one errors, be gone!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: