in reply to random negative toggle function

As another way to do it:

perl -le'print +(-1,1)[rand 2]' # or as a sub sub toggle { (-1,1)[rand 2] }

Of course, that's the short and simple way. I hope this helps you with your problem.