mirror of
https://github.com/wled/WLED.git
synced 2025-07-13 22:06:31 +00:00
Merge pull request #3552 from TripleWhy/seedRandom16
Seed FastLED's RNG
This commit is contained in:
commit
bf4b29b3e3
@ -1714,7 +1714,7 @@ uint16_t mode_multi_comet(void) {
|
|||||||
}
|
}
|
||||||
comets[i]++;
|
comets[i]++;
|
||||||
} else {
|
} else {
|
||||||
if(!random(SEGLEN)) {
|
if(!random16(SEGLEN)) {
|
||||||
comets[i] = 0;
|
comets[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1990,7 +1990,7 @@ uint16_t mode_fire_2012() {
|
|||||||
|
|
||||||
// Step 1. Cool down every cell a little
|
// Step 1. Cool down every cell a little
|
||||||
for (int i = 0; i < SEGLEN; i++) {
|
for (int i = 0; i < SEGLEN; i++) {
|
||||||
uint8_t cool = (it != SEGENV.step) ? random8((((20 + SEGMENT.speed/3) * 16) / SEGLEN)+2) : random(4);
|
uint8_t cool = (it != SEGENV.step) ? random8((((20 + SEGMENT.speed/3) * 16) / SEGLEN)+2) : random8(4);
|
||||||
uint8_t minTemp = (i<ignition) ? (ignition-i)/4 + 16 : 0; // should not become black in ignition area
|
uint8_t minTemp = (i<ignition) ? (ignition-i)/4 + 16 : 0; // should not become black in ignition area
|
||||||
uint8_t temp = qsub8(heat[i], cool);
|
uint8_t temp = qsub8(heat[i], cool);
|
||||||
heat[i] = temp<minTemp ? minTemp : temp;
|
heat[i] = temp<minTemp ? minTemp : temp;
|
||||||
@ -4566,15 +4566,15 @@ class AuroraWave {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void init(uint32_t segment_length, CRGB color) {
|
void init(uint32_t segment_length, CRGB color) {
|
||||||
ttl = random(500, 1501);
|
ttl = random16(500, 1501);
|
||||||
basecolor = color;
|
basecolor = color;
|
||||||
basealpha = random(60, 101) / (float)100;
|
basealpha = random8(60, 101) / (float)100;
|
||||||
age = 0;
|
age = 0;
|
||||||
width = random(segment_length / 20, segment_length / W_WIDTH_FACTOR); //half of width to make math easier
|
width = random16(segment_length / 20, segment_length / W_WIDTH_FACTOR); //half of width to make math easier
|
||||||
if (!width) width = 1;
|
if (!width) width = 1;
|
||||||
center = random(101) / (float)100 * segment_length;
|
center = random8(101) / (float)100 * segment_length;
|
||||||
goingleft = random(0, 2) == 0;
|
goingleft = random8(0, 2) == 0;
|
||||||
speed_factor = (random(10, 31) / (float)100 * W_MAX_SPEED / 255);
|
speed_factor = (random8(10, 31) / (float)100 * W_MAX_SPEED / 255);
|
||||||
alive = true;
|
alive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4659,7 +4659,7 @@ uint16_t mode_aurora(void) {
|
|||||||
waves = reinterpret_cast<AuroraWave*>(SEGENV.data);
|
waves = reinterpret_cast<AuroraWave*>(SEGENV.data);
|
||||||
|
|
||||||
for (int i = 0; i < SEGENV.aux1; i++) {
|
for (int i = 0; i < SEGENV.aux1; i++) {
|
||||||
waves[i].init(SEGLEN, CRGB(SEGMENT.color_from_palette(random8(), false, false, random(0, 3))));
|
waves[i].init(SEGLEN, CRGB(SEGMENT.color_from_palette(random8(), false, false, random8(0, 3))));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
waves = reinterpret_cast<AuroraWave*>(SEGENV.data);
|
waves = reinterpret_cast<AuroraWave*>(SEGENV.data);
|
||||||
@ -4671,7 +4671,7 @@ uint16_t mode_aurora(void) {
|
|||||||
|
|
||||||
if(!(waves[i].stillAlive())) {
|
if(!(waves[i].stillAlive())) {
|
||||||
//If a wave dies, reinitialize it starts over.
|
//If a wave dies, reinitialize it starts over.
|
||||||
waves[i].init(SEGLEN, CRGB(SEGMENT.color_from_palette(random8(), false, false, random(0, 3))));
|
waves[i].init(SEGLEN, CRGB(SEGMENT.color_from_palette(random8(), false, false, random8(0, 3))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5883,7 +5883,7 @@ uint16_t mode_2Dghostrider(void) {
|
|||||||
if (lighter->reg[i]) {
|
if (lighter->reg[i]) {
|
||||||
lighter->lightersPosY[i] = lighter->gPosY;
|
lighter->lightersPosY[i] = lighter->gPosY;
|
||||||
lighter->lightersPosX[i] = lighter->gPosX;
|
lighter->lightersPosX[i] = lighter->gPosX;
|
||||||
lighter->Angle[i] = lighter->gAngle + random(-10, 10);
|
lighter->Angle[i] = lighter->gAngle + ((int)random8(20) - 10);
|
||||||
lighter->time[i] = 0;
|
lighter->time[i] = 0;
|
||||||
lighter->reg[i] = false;
|
lighter->reg[i] = false;
|
||||||
} else {
|
} else {
|
||||||
@ -6744,7 +6744,7 @@ uint16_t mode_puddlepeak(void) { // Puddlepeak. By Andrew Tuline.
|
|||||||
|
|
||||||
uint16_t size = 0;
|
uint16_t size = 0;
|
||||||
uint8_t fadeVal = map(SEGMENT.speed,0,255, 224, 254);
|
uint8_t fadeVal = map(SEGMENT.speed,0,255, 224, 254);
|
||||||
uint16_t pos = random(SEGLEN); // Set a random starting position.
|
uint16_t pos = random16(SEGLEN); // Set a random starting position.
|
||||||
|
|
||||||
um_data_t *um_data;
|
um_data_t *um_data;
|
||||||
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
|
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
|
||||||
|
@ -495,6 +495,16 @@ void WLED::setup()
|
|||||||
initServer();
|
initServer();
|
||||||
DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap());
|
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
|
#if WLED_WATCHDOG_TIMEOUT > 0
|
||||||
enableWatchdog();
|
enableWatchdog();
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user