Math.random():获取0~1随机数 Math.floor() method rounds a number DOWNWARDS to the nearest integer, and returns the result. (小于等于 x,且与 x 最接近的整数.)其实返回值就是该数的整数位:Math.floor(0.666) --> 0Math.floor(39.2783) --> 39 所以我们可以使用Math.floor(Math.random())去获取你想要的一
// 定义一个随机数范围从0 ~页面宽度 var x = parseInt(Math.random() * myCanvas.width); // 定义一个随机数 范围从0 ~页面高度 var y = parseInt(Math.random() * myCanvas.height); // 定义一个数,它可能为正 也可能为负 var num = Math.pow(-1,parseInt(Math.random() * 2) + 1); // 定义一个随机数 决定star的速度 x方向 var
public class Test2 { public static void main(String args[]){ int num; int count[]=new int[21]; for(int i=0;i<10000;i++){ num=(int)(Math.random()*20+0.5); //产生0到20的随机数 count[num]++; //若产生随机数是0,则用count[0]表示它的个数,数组的初始值都为0 System.out.print(num+" "
package com.test; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.lang.Integer; /** * Created by Administrator on 2016/11/13. */ public class ClazzTest { public static void main(String [] args){ sort(5); } //用Math.rando