下面是产生随机数代码:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main ( )
{
int range;
srand (time (NULL));
range = (20 - 4) + 1;
for (int i = 0; i < 10; i++)
cout << rand ( ) % range + 4 << ' ';
cout << endl;
return 0;
}
想问下,假如输出的值时温度值,如何让它输出时幅度不大,也就是说输出1,3,2,4,...
不会输出1度,然后就到21度了,有个幅度。
能帮我解决下吗?