如何生成指定范围内的单精度随机数?如0.000001-0.999999
要求均匀一些

解决方案 »

  1.   

    rand(1, 999999); 在1-999999的随即数Double a = rand(1, 999999)/1000000 ; 
      

  2.   

    rand(1,   999999);   在1-999999的随即数 Double   a   =   rand(1,   999999)/1000000   ;  
    就是这样 难道楼主不能实现 
      

  3.   


    #include <stdlib.h>
    DWORD      b  = rand();// 0--32767
    float   a   =   ((float)b)/1000000.0 
      

  4.   

    目前的范围就到32767, 建议楼主精度改为10000吧; DWORD      b  = rand()%10000;
    float   a   =   ((float)b)/10000.0;
      

  5.   

    double CShapeTryDlg::AverageRandom(double min, double max)//生成随机数
    {
        int minInteger = (int)(min*1000000);
    int maxInteger = (int)(max*1000000);
    int randInteger = rand()*rand();
    int diffInteger = maxInteger - minInteger;
    int resultInteger = randInteger % diffInteger + minInteger;
    return resultInteger/1000000.0;
    }
    我是这么实现的 
    可以实现指定范围内单精度的随机数