产生low--high之间的随机数。
low+rand()%((high-low)+1))
产生0-10之间的随机数。示例代码:
#include <iostream.h>
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
void main(){
//float f1=0.1876;
srand((unsigned)time(NULL));
float f1=rand()%11;
char tmpStr[10];
sprintf(tmpStr,"%.1f",f1);
printf("%s\n",tmpStr);
float d=atof(tmpStr);
printf("string=%sdouble=%lf\n",tmpStr,d);
}