When you mention percentage, is the intention that 90% will give you optimization 9 out of 10 times, and 50% will give you optimization half the time?

I think that <code>(rand()%threshold) == 0)</code> will give you something else. It will give you 1 out of 100, or 1 out of 90, or 1 out of 50, and so on. In the other end of the range it will give you either 1 out of 2 times, or 1 out of 1 (so always), which doesn't seem right. Maybe something like this?

<pre>
((rand() % 100) >= threshold)
</pre>