1 person found this helpful
I do not observe anything of the sort if I correct the code you show and run it. The smaller the limit of the possible outcomes, the more likely the same values will appear, but with a spread of 20 possible values I do not see the amount of repetition you showed over several runs.
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