jeudi 21 juin 2018

AVR Atmega128 random number generator from range

I'm building project for studies on ATmega128 with my friend and we have a problem with random number generator (from 0 to 5), because the function always show the same result. We can't add time.h, because AVR Studio didn't accept this.

Code below:

uint8_t randomNumber(uint8_t r){
r = rand()%5;
return r;
}

other try

uint8_t randomNumber(uint8_t min, uint8_t max){
uint8_t = result;
result = min + rand() % (max+1 - min);
return result;
}

Any ideas? Thanks, Sebastian




Aucun commentaire:

Enregistrer un commentaire