package com;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
class ChouJiang{
private int m_begin,m_end;
public void add(int begin,int end){
m_begin = begin;
m_end = end;
}
public void chouqu(int i){
Set set = new HashSet();
while(true){
int a = (int)(Math.random()*(m_end-m_begin+1))+m_begin;
set.add(a);
if(set.size()==i) break;
}
Iterator r = set.iterator();
while(r.hasNext()){
System.out.println(r.next());
}
}
}
public class MyChoujiang {
public static void main(String[] args) {
ChouJiang a = new ChouJiang();
a.add(10,20);
a.chouqu(8);
}
}
|
|