Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is pretty much straight out of the daily wtf: http://thedailywtf.com/Articles/The-Disgruntled-Bomb.aspx


We have a winner:

#define if(x) if(rand()<0.0001 && (x))


C's rand() function returns an int >= 0, so rand() < 0.0001 will be true only when rand() returns zero. Assuming a pseudorandom number generator that uses all its possible values before repeating, you'll get a 0 approximately every 1 in RAND_MAX times you call rand().


Don't forget the #ifndef DEBUG around it - that would make it ten times harder to track down.


if(rand()>=0.0001 && (x))

that way it will fail extremely rarely and be even harder to detect!


You're right, they either need your change or a switch to ||




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: