Skip to content

Commit

Permalink
Seed FastLED's random functions during startup
Browse files Browse the repository at this point in the history
This allows effects or color palettes that use FastLED's RNG to be
different each time the device is powered on.
  • Loading branch information
TripleWhy committed Nov 27, 2023
1 parent 528b8b1 commit 25c5e82
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,16 @@ void WLED::setup()
initServer();
DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap());

// Seed FastLED random functions with an esp random value, which already works properly at this point.
#if defined(ARDUINO_ARCH_ESP32)
const uint32_t seed32 = esp_random();
#elif defined(ARDUINO_ARCH_ESP8266)
const uint32_t seed32 = RANDOM_REG32;
#else
const uint32_t seed32 = random(std::numeric_limits<long>::max());
#endif
random16_set_seed((uint16_t)((seed32 & 0xFFFF) ^ (seed32 >> 16)));

#if WLED_WATCHDOG_TIMEOUT > 0
enableWatchdog();
#endif
Expand Down

0 comments on commit 25c5e82

Please sign in to comment.