-
Notifications
You must be signed in to change notification settings - Fork 1
/
as183.c
30 lines (28 loc) · 1.27 KB
/
as183.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
/***************************************************************/
/* Program: as183.c */
/* By: Brad Duthie */
/* Description: Takes three seeds and returns a uniform random */
/* This needs to be linked with as183call.c */
/* Compile: gcc as183.c -ansi -Wall -pedantic */
/***************************************************************/
#include<stdlib.h>
/* Below function returns the mod of abs(x)+1*/
/* This is used to verify an acceptable seed*/
int verify_seed(int x){
x=abs(x) % 30000;
return(++x);
} /* Easy way of getting seeds */
double as183(int seeds[]){
double unidev; /* Code below verifies the 3 seeds */
seeds[0] = verify_seed(seeds[0]);
seeds[1] = verify_seed(seeds[1]);
seeds[2] = verify_seed(seeds[2]);
/* Code below gets a decimal to be added to unidev */
seeds[0] = (171 * seeds[0]) % 30269;
seeds[1] = (172 * seeds[1]) % 30307;
seeds[2] = (170 * seeds[2]) % 30323;
/* unidev gets a random uniform number between zero and one */
unidev = seeds[0]/30269.0 + seeds[1]/30307.0 + seeds[2]/30323.0;
/* Return just the decimal, subtract integer of unidev */
return(unidev - (int)unidev);
} /* We now have one random uniform number */