When you use random()
Its going to randomize a number somewhere between 1 and 2. It will never be 2 and very rarely be 1 because it'll give you numbers between 1 and 2 such as 1.2, 1.4 ,1.5
So in your code your looking for when the number = 1 and this won't happen very often.
It seems like you're looking to do it half the time.
So do what Magistross says, it will still randomize the number the same way but then the floor command will round the number down to a whole number. So if you got 1.2 the expression would evaluate to 1 and then the rest of your code would run.