1 /* tunfl2.c CCMATH mathematics library source code.
2 *
3 * Copyright (C) 2000 Daniel A. Atkinson All rights reserved.
4 * This code may be redistributed under the terms of the GNU library
5 * public license (LGPL). ( See the lgpl.license file for details.)
6 * ------------------------------------------------------------------------
7 */
8 /*
9 Test: unfl2() setunfl2()
10
11 Input parameters: s -> unsigned integer: pseudorandom seed
12 n -> integer: sample size
13 */
14 #include <math.h>
15 #include "ccmath.h"
main(int na,char ** av)16 void main(int na,char **av)
17 { double x,xm,ssq; unsigned int s;
18 int n,i,p;
19 if(na!=3){ printf("para: seed(hex) size\n"); exit(-1);}
20 sscanf(*++av,"%x",&s); n=atoi(*++av);
21 printf(" seed= %x\n",s);
22 printf(" sample size= %d\n",n);
23 if(n>1000) p=0; else p=1;
24 /* initialize pseudorandom uniform generator */
25 setunfl2(s);
26
27 xm=ssq=0.;
28 for(i=0; i<n ;++i){
29
30 /* generate a random number on [0,1] */
31 x=unfl2();
32
33 if(p) printf(" %4d %f\n",i,x);
34 xm+=x; x-=.5; ssq+=x*x;
35 }
36 printf(" xmean= %e mean-sq= %e\n",xm/n,ssq/n);
37 }
38 /* Test output
39
40 seed= f53814d1
41 sample size= 20
42 0 0.245931
43 1 0.591419
44 2 0.356836
45 3 0.211378
46 4 0.533397
47 5 0.319682
48 6 0.682214
49 7 0.359572
50 8 0.980991
51 9 0.025067
52 10 0.707456
53 11 0.038997
54 12 0.656155
55 13 0.022205
56 14 0.300957
57 15 0.842522
58 16 0.134199
59 17 0.437262
60 18 0.451750
61 19 0.227005
62 xmean= 4.062498e-01 mean-sq= 7.999734e-02
63 */
64
65