Skip to content

Commit

Permalink
Merge pull request #33 from mhioz/DEV
Browse files Browse the repository at this point in the history
Initialisierung des Zufallsgenerators verbessert
  • Loading branch information
xfjx authored May 12, 2019
2 parents de80c85 + 81d15ff commit 73b5681
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Tonuino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ MFRC522::StatusCode status;
#define buttonDown A2
#define busyPin 4
#define shutdownPin 7
#define openAnalogPin A7

#ifdef FIVEBUTTONS
#define buttonFourPin A3
Expand Down Expand Up @@ -718,7 +719,15 @@ void waitForTrackToFinish() {
void setup() {

Serial.begin(115200); // Es gibt ein paar Debug Ausgaben über die serielle Schnittstelle
randomSeed(analogRead(A7)); // Zufallsgenerator initialisieren

// Wert für randomSeed() erzeugen durch das mehrfache Sammeln von rauschenden LSBs eines offenen Analogeingangs
uint32_t ADC_LSB;
uint32_t ADCSeed;
for(uint8_t i = 0; i < 128; i++) {
ADC_LSB = analogRead(openAnalogPin) & 0x1;
ADCSeed ^= ADC_LSB << (i % 32);
}
randomSeed(ADCSeed); // Zufallsgenerator initialisieren

// Dieser Hinweis darf nicht entfernt werden
Serial.println(F("\n _____ _____ _____ _____ _____"));
Expand Down Expand Up @@ -840,7 +849,6 @@ void previousButton() {
void playFolder() {
Serial.println(F("== playFolder()")) ;
disablestandbyTimer();
randomSeed(millis() + random(1000));
knownCard = true;
_lastTrackFinished = 0;
numTracksInFolder = mp3.getFolderTrackCount(myFolder->folder);
Expand Down Expand Up @@ -1088,8 +1096,6 @@ void loop() {
return;

if (readCard(&myCard) == true) {
// make random a little bit more "random"
randomSeed(millis() + random(1000));
if (myCard.cookie == cardCookie && myCard.nfcFolderSettings.folder != 0 && myCard.nfcFolderSettings.mode != 0) {
playFolder();
}
Expand Down

0 comments on commit 73b5681

Please sign in to comment.