Page 1 of 1

urandom, always same values after reset

Posted: Thu Feb 04, 2021 1:48 am
by Patrice
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

Re: urandom, always same values after reset

Posted: Thu Feb 04, 2021 5:44 am
by jimmo
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.

Re: urandom, always same values after reset

Posted: Mon Feb 08, 2021 11:21 pm
by Patrice
Hi @jimmo,

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