urandom, always same values after reset

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Patrice
Posts: 13
Joined: Mon Feb 10, 2020 3:34 am

urandom, always same values after reset

Post by Patrice » Thu Feb 04, 2021 1:48 am

Hi,

I notice by using urandom module that the values are always the same after a reboot with random(), randint() ...
For example, after a reset, the results after many consecutive urandom.random() instructions are always :
0.7111824
0.4089468
0.09752237

Is someone notice it? Is it normal?

Thanks

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: urandom, always same values after reset

Post by jimmo » Thu Feb 04, 2021 5:44 am

Patrice wrote:
Thu Feb 04, 2021 1:48 am
Is someone notice it? Is it normal?
See https://github.com/micropython/micropython/issues/6347 and https://github.com/micropython/micropython/pull/6558

In summary -- it always used the same default seed (it's a pseudorandom generator, so it's not designed for cryptographic use). The behavior was updated in 1.14 to use a HW random source if available.

In general though, if you're using random it's a good idea to explicitly seed it in a way that is appropriate for your use case.

Patrice
Posts: 13
Joined: Mon Feb 10, 2020 3:34 am

Re: urandom, always same values after reset

Post by Patrice » Mon Feb 08, 2021 11:21 pm

Hi @jimmo,

thanks for your reply, it's clear!
Iuse V1.13, I have to upgrade to V1.14.

Post Reply