lundi 1 juin 2020

What could cause Math.random() to generate the same "random" number on every page reload?

I'm making an electron app and in the renderer process I have a method that calls Math.random(). Just a simple return Math.floor(Math.random() * 1000), nothing special. The problem is that it literally returns the same numbers every time I run the app. 541, 271, 919, 284.. etc. Every time I re-open the app, it's the same numbers in the same order.

What could be the cause of this?

EDIT: This is a weird issue. After some testing I marked down that

  • the issue persist only in the renderer process (written in typescript and compiled using webpack).

  • window.crypto.getRandomValues(array) works as expected.




Aucun commentaire:

Enregistrer un commentaire