How can I generate the same random number in JavaScript and Python? -


in python, if use code:

import random random.seed(123) print(random.random()) 

the first random number 0.052363598850944326, since i'm giving same seed every time run program.

javascript doesn't have built-in way use seeds. i've tried out javascript script called mersenne-twister.js, since that's type of prng python uses. if use same seed, different result in python.

var m = new mersennetwister(123); m.genrand_int32(); 

that code return 0.6964691872708499 first time it's run.

how can use given seed same random number in both python , javascript?

this library/plugin worked me when compared python output javascript output.

https://github.com/davidbau/seedrandom


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -