The only differences between randrange and randint that I know of are that with randrange([start], stop[, step]) you can pass a step argument and random.randrange(0, 1) will not consider the last item, while randint(0, 1) returns a choice inclusive of the last item.
So, I don’t understand why randrange(0, 1) doesn’t return 0 or 1. Why would I use randrange(0, 2) instead of a randrange(0, 1) which does?
The docs on
randrangesay:And
range(start, stop)returns[start, start+step, ..., stop-1], not[start, start+step, ..., stop]. As for why… zero-based counting rules andrange(n)should returnnelements, I suppose. Most useful for getting a random index, I suppose.While
randintis documented as:So
randintis for when you have the maximum and minimum value for the random number you want.