如何产生-1到1区间的随机浮点数??
如题:如何产生-1到1区间的随机浮点数??#include <stdio.h> #include<stdlib.h> int main(void) { int num,i; srand(time(NULL)); for(i=0;i<100;++i) { num=rand()%200+1; printf("NO.%3d=%f\n",i+1,(float)(num/100.0-1.0)); } return 0; }
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int num,i; srand(time(NULL)); for(i=0;i<100;++i) { num=rand()%200+1; printf("NO.%3d=%f\n",i+1,(float)(num/100.0-1.0)); } return 0; }