-
Notifications
You must be signed in to change notification settings - Fork 0
/
rand1.c
69 lines (53 loc) · 1.27 KB
/
rand1.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Link in this file for random number generation using drand48() */
#include <stdio.h>
#include <stdlib.h>
double ran1()
{
double drand48();
return( drand48() );
}
static FILE *pfseed = NULL;
void seedit( char *flag )
{
FILE *fopen(); //, *pfseed = NULL;
unsigned short seedv[3], seedv2[3], *seed48(), *pseed ;
int i;
if( flag[0] == 's' ) {
pfseed = fopen("seedms","r");
if( pfseed == NULL )
{
seedv[0] = 3579 ; seedv[1] = 27011; seedv[2] = 59243;
}
else {
seedv2[0] = 3579; seedv2[1] = 27011; seedv2[2] = 59243;
for(i=0;i<3;i++){
if( fscanf(pfseed," %hd",seedv+i) < 1 )
seedv[i] = seedv2[i] ;
}
fclose( pfseed);
}
seed48( seedv );
printf("\n%d %d %d\n", seedv[0], seedv[1], seedv[2] );
}
else {
pfseed = fopen("seedms","w");
pseed = seed48(seedv);
fprintf(pfseed,"%d %d %d\n",pseed[0], pseed[1],pseed[2]);
}
}
void free_rand1_file()
{
if(pfseed != NULL)
fclose(pfseed);
}
int
commandlineseed( char **seeds)
{
unsigned short seedv[3], *seed48();
seedv[0] = atoi( seeds[0] );
seedv[1] = atoi( seeds[1] );
seedv[2] = atoi( seeds[2] );
printf("\n%d %d %d\n", seedv[0], seedv[1], seedv[2] );
seed48(seedv);
return(3);
}