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

sql - can we replace full join with union of left and right join? why not? -

javascript - Parallax scrolling and fixed footer code causing width issues -

iOS: Performance of reloading UIImage(name:...) -