- petterCode:#include <stdlib.h> #include <time.h> static int s_iLast = INT_MIN; int random(int iMin, int iMax) { int r; do { r = rand() % (iMax - iMin + 1) + iMin; } while (r == s_iLast); s_iLast = r; return r; } int _tmain(int argc, _TCHAR* argv[]) { srand(time(0)); for (int i = 0; i < 20; i++) std::cout << random(0, 5) << std::endl; return 0; }




Reply With Quote