package com.randomOfPackage;
import java.util.Random;
public class RandomClass {
/**
* 产生一个订单随机数,要求永不相等
* @return String
*/
public static String orderNUm()
{
return "";
}
/**
* 产生一个四位的验证码 随机数,
* 用绘图技术绘制出来
* @return String
*/
public static String yanZhengMa()
{
return "";
}
public static void main(String[] args) {
// TODO Auto-generated method stub
/*第二中产生随机数的方法
* static double random()
返回带正号的 double 值,该值大于等于 0.0 且小于 1.0。
*/
double num=Math.random();
System.out.println(num);
/*第三种 Random 类产生随机数
*
* */
Random random=new Random();
/*
* int nextInt()
返回下一个伪随机数,它是此随机数生成器的序列中均匀分布的 int 值。 */
int dNum=random.nextInt();
System.out.println(dNum);
/*
* int nextInt(int n)
返回一个伪随机数,它是取自此随机数生成器序列的、在 0(包括)和指定值(不包括)之间均匀分布的 int 值。 */
dNum=random.nextInt(10);
System.out.println(dNum);//0 到10 之间
Random random2=new Random(System.currentTimeMillis());
int num1=random2.nextInt(100);
int num2=random2.nextInt(100);
System.out.println(num1);
System.out.println(num2);
Random newRandom=new Random();
/* void setSeed(long seed)
使用单个 long 种子设置此随机数生成器的种子。
* */
newRandom.setSeed(100);
int num3=newRandom.nextInt(100);
int num4=newRandom.nextInt(1000);
System.out.println(num3);//5 每次产生的随机数相同
System.out.println(num4);//0
}
}
12.java 中的随机数 Random类和 Math 中 random()函数
最新推荐文章于 2022-11-04 22:18:26 发布