Std::default_random_engine fails on ESP32?


I have some simple code for filling a vector with ascending numbers and then shuffle them (full VS2019 example):

#include <iostream>
#include <algorithm>
#include <stdint.h>
#include <vector>
#include <random>
#include <numeric>

using std::vector;

int main()
	std::default_random_engine defaultRandomEngine{ std::random_device{}() };
	vector<uint16_t> allPixels(285);
	std::iota(begin(allPixels), end(allPixels), 0);	
	std::shuffle(begin(allPixels), end(allPixels), defaultRandomEngine);
    std::cout <<;

On VS2019, the vector is always randomized, the 4th element of the vector is different on almost every run.

When using the same logic on my ESP32, the 4th element is the same on every run.
Also have been playing around with .seed() and some other stuff (took me a while to realize its ESP-related^^).

If someone has an idea what I am doing wrong Im glad for a hint. Otherwise, maybe it helps someone having the same problem.

Please ask the Espressif people what their xtensa-gcc does when asked to create a std::random_device and what the std:.defaullt_random_engine is exactly. Sadly though their repo at GitHub - espressif/gcc does not allow opening issues, so the next best thing is opening it in the framework you’re working with, which you don’t say what it is, but it may be GitHub - espressif/arduino-esp32: Arduino core for the ESP32?

Hm in fact it would be wise though to make sure on is running on the latest compiler version to see if it hasn’t been resolved already. PlatformIO is currenetly lagging behind in regards to the Arduino-ESP32 version (and the accompanying compiler). Please see Support for the latest Arduino v2.0 · Issue #619 · platformio/platform-espressif32 · GitHub for a workaround. If you’re using ESP-IDF, use GitHub - maxgerhardt/pio-espidf-4.4-test as a base project, this uses espressif/toolchain-xtensa-esp32@8.4.0+2021r2.