Skip to content

Commit 9738032

Browse files
authored
examples: use a better source of random (#9)
* switch to RANDOM_REG32 / esp_random() instead micros() * see knolleary#1054
1 parent ee58b1d commit 9738032

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

examples/mqtt_esp8266/mqtt_esp8266.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Basic ESP8266 MQTT example
2+
Basic ESP8266 / ESP32 MQTT example
33
This sketch demonstrates the capabilities of the pubsub library in combination
44
with the ESP8266 board/library.
55
It connects to an MQTT server then:
@@ -22,7 +22,9 @@
2222
#include <ESP8266WiFi.h>
2323
#elif defined(ESP32)
2424
#include <WiFi.h>
25+
#include <esp_random.h>
2526
#define BUILTIN_LED A0
27+
#define RANDOM_REG32 esp_random()
2628
#else
2729
#error Platform not supported.
2830
#endif
@@ -56,7 +58,7 @@ void setup_wifi() {
5658
Serial.print(".");
5759
}
5860

59-
randomSeed(micros());
61+
randomSeed(RANDOM_REG32);
6062

6163
Serial.println("");
6264
Serial.println("WiFi connected");

examples/mqtt_large_message/mqtt_large_message.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Long message ESP8266 MQTT example
2+
Long message ESP8266 / ESP32 MQTT example
33
44
This sketch demonstrates sending arbitrarily large messages in combination
55
with the ESP8266 board/library.
@@ -27,7 +27,9 @@
2727
#include <ESP8266WiFi.h>
2828
#elif defined(ESP32)
2929
#include <WiFi.h>
30+
#include <esp_random.h>
3031
#define BUILTIN_LED A0
32+
#define RANDOM_REG32 esp_random()
3133
#else
3234
#error Platform not supported.
3335
#endif
@@ -59,7 +61,7 @@ void setup_wifi() {
5961
Serial.print(".");
6062
}
6163

62-
randomSeed(micros());
64+
randomSeed(RANDOM_REG32);
6365

6466
Serial.println("");
6567
Serial.println("WiFi connected");

0 commit comments

Comments
 (0)