Idea: It is a bit similar to the sequencing method, relying only by an array, generating the last N bit of the last array is the required N random number. For example, from 1 to 10 non-repetable random numbers, the initial time: 1 2 3 4 5 6 7 8 9 10 | Each of the first pass, the Rander is selected in 0- (Ni-1), N is 10, i is the number, set 3: 1 2 10 4 5 6 7 8 9 | 3 Commissioning Ni-1 with the Rander. Then carry out the second time. i , so randomly does not repeat, set 31 2 9 4 5 6 7 8 | 10 3 third, hypotheses 3: 1 2 8 4 5 6 7 | 9 10 3 Results Three non-repetitive random numbers are 3, 10, 9
Code: template class myrandom {private: public: myrandom () {srand (null); // init random} void rand (Type * Source, int LENGTH, INT RANDNUMBER) {TYPE Temp; for (int i = 0; i