标签:
#include<iostream>
#include<ctime>
#include<cstdlib>
using
namespace
std;
double
random(
double
,
double
);
int
main()
{
srand
( unsigned(
time
(0) ) );
//srand(time(NULL));
for
(
int
j = 0; j < 10; j++)
cout <<
"No."
<< j+1 <<
":"
<<
int
(random(0,10)) << endl;
return
0;
}
double
random(
double
start,
double
end)
{
return
start + (end - start) *
rand
() / (RAND_MAX + 1.0);
}
//从此处采取点斜式子,将返回值范围限定至0-9//的整数,倘若要生成10,(RAND_MAX+1.0)改成(RAND_MAX)
/*运行结果
*No.1:3
*No.2:9
*No.3:0
*No.4:9
*No.5:5
*No.6:6
*No.7:9
*No.8:2
*No.9:9
*No.10:6*/
标签:
原文地址:http://www.cnblogs.com/lijinji/p/5873644.html