China Naming Network - Ziwei Dou Shu - PPT random multiple choice questions

PPT random multiple choice questions

The simplest non-repetitive random number algorithm is like this.

If you want to take 0-9 random numbers,

Then define an array of 10 elements to store the values of 0-9. Then define a number to store the starting subscript of the valid elements of the array.

Then take a random number ranging from 0- the number of valid elements in the current array. The first time is 0- 10 (that is, take a random number that contains 0 and does not contain 10).

Suppose you take 5 for the first time.

Then output the fifth element in the array, and then set the fifth element as the starting subscript of the effective element (0 at this time), and set the starting subscript of the effective element as-1 (it doesn't matter whether you do this step or not. ), the effective element of the array subscripts+1.

Continue to take 1-9, assuming that the next random number is 5, the fifth element is output, and then the fifth element is set as the initial subscript of the effective element (at this time, 1), and the subscript of the array effective element is+1.

Continue to take 2-9, assuming that the next random number is 5, then output the fifth element, and then set the fifth element as the starting subscript of the effective element (2 at this time), and the array effective element subscript+1.

And so on until 10 random numbers and 10 numbers are taken out, and the cycle ends.