Random number function that factors into account Cumulative Frequency

喜你入骨 提交于 2019-12-11 05:30:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!