随机数是10的倍数 [英] Making a random number that's a multiple of 10

查看:109
本文介绍了随机数是10的倍数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在两个范围之间创建一个随机数,该范围是10的倍数.

I'm looking to create a random number between two ranges that is a multiple of 10.

例如,如果我向函数提供参数0, 100,它将返回以下数字之一:

For example, if I fed the function the parameters 0, 100 it would return one of these numbers:

0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100

但没有像6355那样的东西.

but nothing like 63 or 55.

是的,我知道这违反了真正的随机性",但是我只需要一种快速简便的方法就可以得到两个范围之间的10的倍数.

And yes I'm aware this defeats the point of true "randomness", but I just need a quick easy way to get a number that's a multiple of 10 between two ranges.

谢谢. :)

推荐答案

我想它可以提供帮助:

var randomnumber=Math.floor(Math.random()*11)*10

这篇关于随机数是10的倍数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆