-
Notifications
You must be signed in to change notification settings - Fork 0
/
rand2.c
52 lines (40 loc) · 884 Bytes
/
rand2.c
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
46
47
48
49
50
51
/* Link in this file for random number generation with rand() */
#include <stdio.h>
#include <stdlib.h>
double
ran1()
{
int rand();
return( rand()/(RAND_MAX+1.0) );
}
void seedit( const char *flag)
{
FILE *fopen(), *pfseed;
unsigned int seed2 ;
if( flag[0] == 's' ) {
pfseed = fopen("seedms","r");
if( pfseed == NULL ) {
seed2 = 59243; }
else {
fscanf(pfseed," %d",&seed2);
fclose( pfseed);
}
srand( seed2) ;
printf("\n%d\n", seed2 );
}
else {
pfseed = fopen("seedms","w");
fprintf(pfseed,"%d \n",rand());
fclose( pfseed); /* added 8 Sept 2014, thanks to Feng Gao */
}
}
int
commandlineseed( char **seeds)
{
unsigned int seed2 ;
void srand(unsigned int seed);
seed2 = atoi( seeds[0] );
printf("\n%d\n", seed2 );
srand(seed2) ;
return(1);
}