Running a program in a debugger introduces a fair amount of overhead and delay. As for your issue with rand(), it's because you're not seeding it with a unique value (ie. the system time is a very commonly used value because it will generally be different from one use of a program to the next in any normal circumstances). By design, a pseudo-random number algorithm must produce the same sequence of numbers any time it is used with the same initial value (seed).