Generating a random Number (0 or 1)

Hello,

every 100ms i want to "have" a random number (0 or 1), but the results of my code are a little bit "boring:

2222222211122222211122122211211222111111222112111221121112221221112222211122122211121122

I would like to have numbers like this:

1212212212111211122122121212212212212211121112121222221212122111211122221211211121212221

This is my code:

void setup(){
  Serial.begin(9600);
}

void loop() {
  randomSeed(millis());
  byte Zufallszahl=random(1,3);
  Serial.print(Zufallszahl);
  delay(100);
}

When i change millis() to analogRead(0) it is getting "better", but it`s still not randomized enough for me.

I dont want to use additional hardware.** **I dont want to talk about additional hardware.

Greetz Chris

When i change millis() to analogRead(0) it is getting "better", but it`s still not randomized enough for me.

The randomSeed() function is supposed to be called once. Not once for each random number you want.

Try the Entropy Library from wanderson. If it does what he says it does, this little bit of software should solve your problem.

I`ll have a closer look! :slight_smile:

Thanks!

Greetz Chris