Not much to say, the code is not many, the algorithm is simple
Method One:
/** * Algorithm for winning numbers, the method will fill the last number to this position after each draw to a winning number, implementing the non-repeating extraction. * <p> * After many tests, this method at Big data speed is slightly better than {@link #booleans ()}, small data gaps can be ignored * * @return */public int[] Deletelast () {if (prize <= 0) return new int[0];int[] Nums = new int[max];for (int i=0; i<max; i++) {nums[i] = i+1;} Int[] Prizes = new Int[prize];int ZJ = 0;for (int i=0; i<prize; i++) {ZJ = (int) (Math.random () * max);p rizes[i] = nums[z J];NUMS[ZJ] = Nums[--max];} return prizes;}
Method Two:
/** * Gets the algorithm of the winning number, method sets the value of the original array to be Boolean, the value is set to true in the extraction, and the implementation does not repeat the extraction. * <p> * After many tests, this method at Big data speed is slightly worse than {@link #deleteLast ()}, small data gaps can be ignored * * @return */public int[] Booleans () {if (prize <= 0) return new int[0];boolean[] Nums = new boolean[max];for (int i=0; i<max; i++) {Nums[i] = false;} Int[] Prizes = new Int[prize];int Zjcount = 0;int ZJ = 0;while (Zjcount < prize) {ZJ = (int) (Math.random () * max); if (!nu MS[ZJ]) {NUMS[ZJ] = true;prizes[zjcount++] = ZJ;}} return prizes;}
Reference: http://bbs.csdn.net/topics/280080151
JAVA Two simple lottery algorithm