12.java 中的随机数 Random类和 Math 中 random()函数

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
		
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值