/* zufallszahlen_01.c * ATmega88 @ 8MHz */ #include #include <avr/io.h> uint16_t zufallszahl, zz, wuerfelzahl, eins=0, zwei=0, drei=0, vier=0, fuenf=0, sechs=0; int main(void) { for (uint16_t i=0; i<100; i++) // 100 Durchläufe erzeugen { zufallszahl = rand(); // Funktion rand() aufrufen und Rückgabewert in zufallszahl speichern zz = zufallszahl % 6; // Rest aus Modulo 6 berechnen (0 bis 5) wuerfelzahl = zz + 1; // +1 für 1...6 if (wuerfelzahl == 1) eins ++; else if (wuerfelzahl == 2) zwei ++; else if (wuerfelzahl == 3) drei ++; else if (wuerfelzahl == 4) vier ++; else if (wuerfelzahl == 5) fuenf ++; else if (wuerfelzahl == 6) sechs ++; } }