Skip to content

Instantly share code, notes, and snippets.

@avr-programmierung
Created May 16, 2019 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avr-programmierung/9b0a0e4b0bcb088c4731c8e67bb6980e to your computer and use it in GitHub Desktop.
Save avr-programmierung/9b0a0e4b0bcb088c4731c8e67bb6980e to your computer and use it in GitHub Desktop.
ATmega88 @ 8MHz Zufallszahlen
/* 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 ++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment