JavaScript中Math.random的种子设定方法
CodeWars上有这么个题目: 《Don't rely on luck》
的奇葩题目,先看一下题目描述:
Description:
The test fixture I use for this kata is pre-populated.
It will compare your guess to a random number generated in JavaScript by:Math.floor(Math.random() * 100 + 1)
You can pass by relying on luck or skill but try not to rely on luck.
“The power to define the situation is the ultimate power.” - Jerry Rubin
Good luck!
给出的Test Case:
1 |
var lucky_number = Math.floor(Math.random() * 100 + 1); |
出题者大约是想让每次随机数与你guess到的数字相同,So ‘Don’t rely on luck’.
这是一个大坑,原本读完题后百思不得其解,当UnSolution后,心里真的是万马奔腾。
This is solution
1 |
Math.random=function(n){ return 0;} |