package xuwb;
import org.junit.Before;
import org.junit.Test;
import org.junit.After;
import java.util.Random;
/**
* Created by IntelliJ IDEA.
* User: Byron.Xu
* Date: 2008-9-23
* Time: 14:19:25
* To change this template use File | Settings | File Templates.
*/
public class RandomTest {
private Random random;
private int min;
private int max;
@Before
public void init() {
random = new Random();
min = 1;
max = 3;
}
@Test
public void randomTest() {
for (int i = 0; i < 10; i++) {
// System.out.println(Math.abs(random.nextInt()) % 50);
//0---10
// System.out.println(" ---------- " + Math.abs(random.nextInt())% 10);
// w
// System.out.println(" ========== " + (random.nextInt(17)+9));
/**
* 得到某一个区间的随机数公式
* (数据类型)(最小值+Math.random()*(最大值-最小值+1))
*/
System.out.println(" >>>>>>>>>>> " + (int)(min+Math.random()*(max-min+1)));
}
}
@After
public void destory() {
random = null;
}
}
随机数的公式,没什么说的,直接用,哈哈