1、虽然生成不重复的随机数算法,但是百度一下后还是发现是重复计数的算法居多,由于此算法可能会产生万中无一的死循环,所以改进了此算法,虽然改进的算法也可能产生万中无一的有规律的随机数,但是能够保证程序的可运行性。以下是用 java 写的算法源代码:import java.util.Random;public class Rand int array, Rarry;int subscript, count;Random r;/* init*/public Rand(int start, int end, int count) subscript = end - start + 1;array = ne
2、w intsubscript;Rarry = new intcount;r = new Random();for (int i = 0; i array.length; i+) arrayi = i + start;this.count = count;/* for show*/public void showOldArray() System.out.println(“nold array:“);for (int i : array) System.out.print(i + “ “);public void showDeliverArray() System.out.println(“ndeliver array:“);for (int i : Rarry) System.out.print(i + “ “);/* make random*/public void make() for (int i = 0; i count; i+) int tempSub = r.nextInt(subscript);Rarryi = arraytempSub;arraytempSub = arraysubscript - 1;subscript-;