Skip to content

Commit 60bac6d

Browse files
committed
GoL faster random during setup
1 parent f70e87e commit 60bac6d

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

wled00/FX.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5375,29 +5375,17 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
53755375
memset(cells, 0, dataSize);
53765376
random16_set_seed(strip.now>>2); //seed the random generator
53775377
unsigned cIndex = 0;
5378-
uint32_t xorshift32_state = random16();
5379-
const uint32_t threshold = (UINT32_MAX / 3);
5380-
for (unsigned y = 0; y < rows; ++y) for (unsigned x = 0; x < cols; ++x, ++cIndex) {
5378+
for (unsigned y = 0; y < rows; ++y) {
53815379
#if defined(ARDUINO_ARCH_ESP32)
5382-
// bool setAlive = esp_random() < 1374389534; // ~32%
5383-
// bool setAlive = random16(100) < 32;
5384-
// bool setAlive = (rand() & 0xFF) < 86;
5385-
// bool setAlive = random8(3);
5386-
uint32_t myrand = xorshift32_state;
5387-
myrand ^= myrand << 13;
5388-
myrand ^= myrand >> 17;
5389-
myrand ^= myrand << 5;
5390-
xorshift32_state = myrand;
5391-
bool setAlive = (myrand < threshold);
5392-
#else
5393-
bool setAlive = random16(100) < 32;
5380+
random16_add_entropy(esp_random() & 0xFFFF);
53945381
#endif
5395-
if (setAlive) {
5396-
grid.setCell(cIndex, x, y, true, wrap);
5397-
cells[cIndex].toggleStatus = 1; // Used to set initial color
5382+
for (unsigned x = 0; x < cols; ++x, ++cIndex) {
5383+
if ((random16() & 0xFF) < 82) { // ~32%
5384+
grid.setCell(cIndex, x, y, true, wrap);
5385+
cells[cIndex].toggleStatus = 1; // Used to set initial color
5386+
}
5387+
else cells[cIndex].superDead = 1;
53985388
}
5399-
else cells[cIndex].superDead = 1;
5400-
54015389
}
54025390
}
54035391

0 commit comments

Comments
 (0)