I should have been more clear that was a vastly oversimplified example. That code specifically (after you change rand to random, whoops) won't usually produce the same value in a row more than twice. But then I've got code (all too long to post of course) with function calls, loops, etc, generating the same number six or more times in a row in some cases.
edit: Well, in this case it was a convoluted and stupid bug, actually unrelated to the random number generation. So my bad >_< . I've had similar problems several times in the past, though they were in areas less obvious to the end user; I don't remember if or how I resolved them, so for all I know they were similarly deceptive bugs