是否可以在Java中使用Math.Random()来获取一系列数字,例如10、20、30、40...或100、200、300...。 我当前的实现是 Math.Random()*3*100,因为我认为这将使我得到最多 300 个可被 100 整除的数字。
最佳答案
此代码在步骤 10 中返回一个随机数。0 被排除在外,但如果您想添加它,请去掉 Math.random() 行上的 +1。
int step = 10;
int random = (int)(Math.random()*10+1)*step; //10 is the number of possible outcomes
System.out.println("Random with step " + step + ":" random);
关于Java Math.Random() 用于一系列数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33965780/