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.
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
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM