Python randint not equal to 0 -


this question has answer here:

i trying use random.randint randomly generate single int between range, e.g. randint(-2,2), however, possibly generate 0, not expected, wondering there way make not equal 0. or use loop until randint(-2,2) not generate 0, , output.

cheers

don't use randint() then; picks integer continuous range of values, not discrete set.

use random.choice() function instead, passing in list of just integers want pick from:

random.choice([-2, -1, 1, 2]) 

this'll return random value list.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -