Seeding the random number generator in Javascript

后端 未结 13 1397
野趣味
野趣味 2020-11-22 09:28

Is it possible to seed the random number generator (Math.random) in Javascript?

13条回答
  •  清酒与你
    2020-11-22 10:12

    A simple approach for a fixed seed:

    function fixedrandom(p){
        const seed = 43758.5453123;
        return (Math.abs(Math.sin(p)) * seed)%1;
    }
    

提交回复
热议问题