Use a combination of Math.floor()
and Math.random()
.
结合使用Math.floor()
和Math.random()
。
This simple one line of code will return you a number between 1 and 6 (both included):
这个简单的代码行将为您返回1到6之间的数字(均包括在内):
Math.floor(Math.random() * 6 + 1)
There are 6 possible outcomes here: 1, 2, 3, 4, 5, 6.
这里有6种可能的结果:1、2、3、4、5、6。
翻译自: https://flaviocopes.com/how-to-generate-random-number-between/