问题
The census dataset for last name and first name occurrences provides cumulative frequency
and frequency
. How do I go about getting a random name with the likelyhood of it being chosen that of the occurrence in the real world?
回答1:
Just generate a random real number in the 0-100 range and look for the corresponding entry in the cumulative frequency dataset.
Example, say your random number gives x = 19.41
. Look into the table (sorted by cumulative frequencies) and locate the first one that has a value greater or equal than x
WALLACE 0.081 19.315 106
WOODS 0.080 19.395 107
COLE 0.080 19.476 108
WEST 0.080 19.555 109
JORDAN 0.078 19.634 110
in this example, you obtain 'COLE'
来源:https://stackoverflow.com/questions/8977156/random-number-function-that-factors-into-account-cumulative-frequency