Ad

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.

Ad

Answer

Turns out that calling cryptico.generateRSAKey() calls seedrandom.js's Math.seedrandom(), which overrides Math.random().

Case closed. Related: https://github.com/wwwtyro/cryptico/issues/20

Ad
source: stackoverflow.com
Ad