Python + onCook Question

I want to use noise to randomly fire a Pulse event. There’s probably a bunch of ways to do this, so I’d be open to all options. The way I’m trying to do it is to create a Noise Chop → Logic Chop (to convert to 0/1) → Script Chop. Inside the Script Chop I have the following python code:

[code]prevVal = -1
def onCook(scriptOp):
global prevVal
val = op(‘logic1’)[‘chan1’]

print(prevVal, val)

if val != prevVal:
	print("Diff")
	prevVal = val
else:
	print("Same")

scriptOp.clear()
return[/code]

What I’d expect is to see the prevVal differ from the val the first time the logic goes high. However the result I’m getting is every value is hitting the “Same” statement.

python >>> 0.0 0.0 Same python >>> 1.0 1.0 Same

Is this an issue with my code? A misunderstanding of how a Cook is handling the python code? Or most importantly, is there an easier way to emit a pulse randomly?

Weird. Can you post this piece of your network please? I’d like to test this.