package com; import java.util.ArrayList; import java.util.List; //生成从指定数到指定数的指定个数的不重复的随机数 public class MathUtits { //产生sumNumber个,从startNumber到endNumber的不重复随机整数集合 public static List<Integer> GetIntMathNumber(int startNumber,int endNumber,int sumNumber){ List<Integer> SumNumber = new ArrayList<Integer>(); while(SumNumber.size() < sumNumber){ Integer num = null; if(endNumber - startNumber < 10){ num = (int)Math.round(Math.random()*10); }else{ num = (int)Math.round(Math.random()*(endNumber-startNumber)+startNumber); } if(!SumNumber.contains(num)){ SumNumber.add(num); //System.out.println(num); } } return SumNumber; } //产生sumNumber个,从startNumber到endNumber的不重复随机浮点数集合 public static List<Double> GetDoubleMathNumber(double startNumber,double endNumber,int sumNumber){ List<Double> SumNumber = new ArrayList<Double>(); while(SumNumber.size() < sumNumber){ Double num = null; if(endNumber - startNumber < 10){ num = (double)Math.round(Math.random()*10); }else{ num = (double)Math.round(Math.random()*(endNumber-startNumber)+startNumber); } if(!SumNumber.contains(num)){ SumNumber.add(num); //System.out.println(num); } } return SumNumber; } /** * @param args */ public static void main(String[] args) { GetIntMathNumber(1,15,6); } }