Skip to content

std::random_device always returns constant value #8201

Closed
@Zhu-jiatong

Description

@Zhu-jiatong

Board

Irrelevant

Device Description

ESP32 NodeMCU

Hardware Configuration

Bare ESP32 Board

Version

v2.0.9

IDE Name

Visual Micro (Arduino IDE)

Operating System

Windows 11

Flash frequency

80Mhz

PSRAM enabled

no

Upload speed

115200

Description

I intended to use a real random number generator for cryptographic purposes. So, I choose std::random_device, which should be a platform independent way that is able to return real random numbers.

However, the generator produces the same value 3499211612 every time the ESP32 is powered on, which is not random.

Sketch

#include <random>
void setup()
{
 Serial.begin(115200);
 ... // wait until Serial is ready;
 std::cout << std::random_device()();
}

Debug Message

Output on serial monitor every time the board is powered on: `3499211612`

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions