java从指定数组中取不重复的7个随机数
如何用java从指定数组中取不重复的7个随机数,以下是我写的代码,但是是有重复的,哪位大侠赐教一下如何使用Random类的种子,帮我实现不重复的随机数。。。
import java.util.*;
public class Lottery {
public static void main(String[] args)
{
int[] data1 = {3,5,6,8,9,15,18,24,27,30,32};
Random r=new Random();
StringBuffer str1=new StringBuffer();
for(int i=0;i<6;i++)
{
str1.append(data1[r.nextInt(11)]);
}
System.out.println(str1);
}
}