1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include <iostream>
using
namespace
std;
#include <stdlib.h>
#include <time.h>
#define MIN 1 //随机数产生的范围
#define MAX 10
int
main()
{
int
i;
srand
((unsigned)
time
(0));
cout<<
"Ten random numbers from "
<<MIN<<
" to "
<<MAX<<
" :/n"
<<endl;
for
(i=0; i<10; i++)
//产生随机数
{
cout<<MIN + (
int
)MAX *
rand
() / (RAND_MAX + 1)<<
"/t"
;
}
cout<<endl;
return
0;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include <iostream>
using
namespace
std;
#include <stdlib.h>
#include <time.h>
#define MIN 0 //随机数产生的范围
#define MAX 99
int
main()
{
int
i;
srand
((unsigned)
time
(NULL));
cout<<
"Ten random numbers from "
<<MIN<<
" to "
<<MAX<<
" :/n"
<<endl;
for
(i=0; i<10; i++)
//产生随机数
{
cout<<MIN +
rand
() % (MAX + MIN - 1)<<
"/t"
;
}
cout<<endl;
return
0;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#include <iostream>
using
namespace
std;
#include <stdlib.h>
#include <time.h>
int
main()
{
int
i;
for
(i=0; i<10; i++)
//产生10个随机数
{
cout<<
rand
()<<
"/t"
;
}
cout<<endl;
return
0;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#include <iostream>
using
namespace
std;
#include <stdlib.h>
#include <time.h>
int
main()
{
int
i;
srand
((unsigned)
time
(NULL));
//初始化随机数种子
for
(i=0; i<10; i++)
//产生10个随机数
{
cout<<
rand
()<<
"/t"
;
}
cout<<endl;
return
0;
}
|