The code just calculates a new random seed every 2 seconds and uses that to generate a random number between 0 and 1, which it uses to decide whether the opacity should be off or on. If it should be on, it also makes sure that it has been on for less than .5 seconds (holdTime) or else it turns opacity off.
Yours seems to have several problems. First, your seed calculation will produce a new seed every frame (not very useful). Then you generate a random number, but don’t assign it to a variable. Then you test the layer’s opacity (which will always be the same value unless you have keyframed it). Then you test the opacity value again (by the way the JavaScript equality test is == not =) and depending on the result you either set holdTime to .5 (and then never use that value) or set opacity to 2 (?)
I’m guessing you’re confused by the fact that an expression can’t pass info to itself from one frame to the next. Any time you reference the value of the property that the expression is applied to you get the static (or keyframed) value, not the one generated previously by the expression.
Dan