-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.cpp
47 lines (32 loc) · 841 Bytes
/
random.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* srand example */
#include <stdio.h> /* printf, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
void shuffle(int array1[], int size)
{
int i, temp, random, last;
for (i = 0; i < size; i++)
array1[i] = i + 1;
for (last = size; last > 1; last--)
{
random = rand() % last;
temp = array1[random];
array1[random] = array1[last - 1];
array1[last - 1] = temp;
}
}
int main ()
{
/* printf ("First number: %d\n", rand()%100);
srand (time(NULL));
printf ("Random number: %d\n", rand()%100);
srand (1);
printf ("Again the first number: %d\n", rand()%100);
*/
int array[200],size;
size =10;
shuffle(array,size);
for(int i=0;i<size;i++)
printf("%d ",array[i]);
return 0;
}