对自己的“平均随机数封装类”的测试

来源:互联网 发布:网络架构图怎么做 编辑:程序博客网 时间:2024/05/19 03:22
软件架构师何志丹

对自己的“平均随机数封装类”的测试。

测试[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


原创粉丝点击