Randomly generate pseudo functions that do not repeat recording

zhaozj2021-02-11  195

Principle: Use a temporary array to save the random range data (scope data) index or identifier, randomly generate the index of the temporary array with RND. Verify the data corresponding to the temporary array index, to be recorded for the airline, and repeat the random number to repeat the verification operation until the data corresponding to the temporary array index is not empty, then a record variable record corresponding to the range data identifier And empty this data. Then perform the next random operation.

Pseudo function:

'####' ## function parameter '## Range data array: One-dimensional array. '## Randomly selected data volume: integer. Function myrnd (range data array, random selection data) '################################################################################################################################################################################################################################################################################# ########################################################################################################################################################################################################################################################################################################### (Range Data Array) Cyclic Identification = True IF Range Data Arrange Dimension> Random Selection Data Queue Then 'If the amount of data of randomly selected is greater than the range of data array, it is not randomly read. All cloth is listed. Randomize Timer Random Index = FIX (RND * (Ran Data Arrange Dimension 1)) WHILE Cycle Identifier IF Range Data Arrse (Random Index MOD Range Data Archive) <> "" "The" is not empty, indicating that it is not random selection Over. Random index = range data array (random index mod range data array) IF random results = "" THEN 'random results are separated by each random value. Random Results = Random Results &; "," End IF Random Results = Random Results &; Range Data Arrange (Random Index) Range Data Array (Random Index) = "" Empty This data is randomable. Cycle Identification = false 'ends cycle. END IF IF Random Index> Range Dimension * 3 Then 'If the random index is larger than three times the number of range dimensions of the range data, it has been spent three times in the range of data array dimensions. Cycling Identification = false end if Wend end ifend function

Application: Use data sheet records that are not repeated at random. Use getRows to replace the ID ID in the data table to a two-dimensional array, then use this function to randomly select the specified number of ID numbers to "," separated, and then use the IN condition type to read the data that meets the random ID number. . Stopically do not repeat data. Put all data into one-dimensional data, then use this function to pick up the randomly selected.

转载请注明原文地址:https://www.9cbs.com/read-5576.html

New Post(0)