c语言或者c++如何生成在(0,1)之间间隔为0.125均匀分布的随机数,等概率生成随机数?
1条回答 默认 最新
- threenewbee 2019-02-11 16:15关注
那么你只要生成0-8的随机整数,然后除以8即可。
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int x,num; srand(time( NULL )); x =1 + (rand()%8); printf("%f",x/8.0); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 4无用 3