软件架构师何志丹
对自己的“平均随机数封装类”的测试。
测试[0到0x1000]个种子,每个种子产生0x1000个随机数。
CRand rand;
int nums[0x10000]={0};
for( int j = 0 ; j < 0x10000 ; j++ )
{
rand.m_seed = j ;
for(int i = 0 ; i < 0x10000 ; i++ )
{
const int r = rand.rand();
ASSERT( ( r >= 0 ) && ( r <= 0XFFFF));
nums[r]++;
}
}
std::sort(nums,nums+0x10000);
ASSERT((64514==nums[0]) && (64938==nums[600]) && (66138==nums[0xffff-600]) &&(66568==nums[0xffff]));
float f1 = 1.0*nums[0xffff-600]/nums[600];
float f2 = 1.0*nums[0xffff-3000]/nums[3000];
结果:f1=1.018 f2=1.013
2021年目标:完成新书《闻缺陷则喜》,本博客右上公告有下载、阅读链接。