import java.util.Random;/** * Created by kdoulf on 2017/4/6. */public class RandomTest { public static void main(String[] args){ //10以内的随机数可以使用两种方法,一个是Random一个是Math.random()*10,Math.random是0-1的随机数 //其实Math.random 内部也是类似的调用的Randome randome = new Random(). //private static final class RandomNumberGeneratorHolder { // static final Random randomNumberGenerator = new Random(); //} //10以内的随机数,double的 for (int i = 0; i < 10; i++) { double v = Math.random() * 10; System.out.println(v); System.out.println(Math.ceil(v)); } //10以内的随机数 Random random = new Random(); for (int i = 0; i < 10; i++) { int i1 = random.nextInt(9)+1; System.out.println(i1); } }}