Div_OR
Div_OR

Reputation: 33

How to create non equal variables in python

I need to create 3 integers like this:

            for i in range(1000):
                 x = random.randint(0, 4)
                 g = random.randint(0, 4)
                 z = random.randint(0, 4)

How could I check if x, g, z are not equal I tried if x != r and z and g: but didn't work, it just gives me 3 random integers, So is there sth with my code.

Upvotes: 0

Views: 61

Answers (1)

John Coleman
John Coleman

Reputation: 52008

By far the easiest way to get three distinct randomly chosen integers in the range 0 to 4 is to use:

x,y,z = random.sample(range(5),3)

Upvotes: 8

Related Questions