+ 1
[SOLVED] Seeding JS Math.random()
Is there a simple way to seed the JS Math.random() so that it will return the same number each time just like Python’s random.seed() works?
6 odpowiedzi
+ 7
no such option with the Math.random() function but try looking here for alternative
https://stackoverflow.com/questions/424292/seedable-javascript-random-number-generator
+ 2
Nathan Lewis I've been using the library suggested in one of my codes: https://code.sololearn.com/W01q2RTV4aXB/?ref=app
+ 2
Nathan Lewis exactly like here: https://github.com/davidbau/seedrandom/blob/released/README.md
I've included it from cdnjs, initialized the generator with passing to Math.seedrandom an array of numbers and then using Math.random to get my numbers.
+ 2
🤖 Basile Laderchi perfect, I messed up on the script placement. works perfectly! thanks so much(:
0
thanks everyone! 🤖 Basile Laderchi i was having trouble with seedrandom, could you explain how it works?
edit: Nevermind i put the script in the wrong place😂😂
0
Nathan Lewis you're welcome