Random
-
Hallo ich wollte gerne eine auswahl zwischen 0,2,6,8.
Und dann zufällig eine aus diesen 4 Zaghel aus wählen.
Wie schreibe ich das in c++?MfG Sampey
-
#include <stdio.h> #include <windows.h> #include <tchar.h> #include <time.h> int GetRand() { static const int val[4] = {0,2,6,8}; int i = rand(); return val[((i*4)/RAND_MAX)]; } int _tmain() { srand((unsigned)time(NULL)); while(1) { _tprintf(_T("%d "), GetRand()); Sleep(50); } return 0; }