lic int nextInt(int n)
该方法的作用是生成一个随机的int值,该值介于[0,n)的区间,也就是0到n之间的随机int值,包含0而不包含n。
直接上代码:
package org.xiaowu.random.demo;
import java.util.Random;
import org.junit.Test;
public class RandomDemo {
@Test
public void Demo(){
Random rnd = new Random();
int code = rnd.nextInt(8999) + 1000;
System.out.println("code:"+code);
}
@Test
public void Demo1(){
Random r = new Random();
int nextInt = r.nextInt();
Random r1 = new Random(10);
int nextInt2 = r1.nextInt();
System.out.println("nextInt:"+nextInt);
System.out.println("nextInt2:"+nextInt2);
}
/**
* 生成[0,1.0)区间的小数
*
*/
@Test
public void Demo2(){