您的位置:首页 > 编程语言 > Java开发

java生成随机数

2010-10-11 14:55 302 查看
import java.util.Random;

public class randomClass {

/**
* @param args
*/
// public static void main(String[] args) {
// TODO Auto-generated method stub
// method 1 弊端,100000以下的数字将取不到。
// int n = 0 ;
// while(n < 100000){
// n = (int)(Math.random()*1000000);
// }
// System.out.println(n);

// method2 弊端,同 method 1
// System.out.println((int)((Math.random()*9+1)*100000));

// method 3 弊端,同 method 1
// double b = Math.random();
// while (b < 1) {
// b *= 10;
// }
// System.out.println((int) (b * 100000));

// method 4 可以输出100000以下的数字
// Random random = new Random();
// String result="";
//
// for(int i=0;i<6;i++){
// result+=random.nextInt(10);
// }
// System.out.print(result);

// method 5 同 method 4
// Random r = new Random();
// Double d = r.nextDouble();
// System.out.println(d);
// String s = d + "";
// s=s.substring(3,3+6);
// System.out.println(s);


// System.out.println(NextInt(100000,999999));
// }

// public static int NextInt(final int min, final int max)
// {
// Random rand;
// rand= new Random();
// int tmp = Math.abs(rand.nextInt());
// return tmp % (max - min + 1) + min;
// }


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: