source: project/release/4/srfi-27/trunk/WELL512a.c @ 34855

Last change on this file since 34855 was 34855, checked in by Kon Lovett, 4 years ago

st trk

File size: 1.9 KB
Line 
1/* ***************************************************************************** */
2/* Copyright:      Francois Panneton and Pierre L'Ecuyer, University of Montreal */
3/*                 Makoto Matsumoto, Hiroshima University                        */
4/* Notice:         This code can be used freely for personal, academic,          */
5/*                 or non-commercial purposes. For commercial purposes,          */
6/*                 please contact P. L'Ecuyer at: lecuyer@iro.UMontreal.ca       */
7/* ***************************************************************************** */
8
9#define W 32
10#define R 16
11#define P 0
12#define M1 13
13#define M2 9
14#define M3 5
15
16#define MAT0POS(t,v) (v^(v>>t))
17#define MAT0NEG(t,v) (v^(v<<(-(t))))
18#define MAT3NEG(t,v) (v<<(-(t)))
19#define MAT4NEG(t,b,v) (v ^ ((v<<(-(t))) & b))
20
21#define V0            STATE[state_i                   ]
22#define VM1           STATE[(state_i+M1) & 0x0000000fU]
23#define VM2           STATE[(state_i+M2) & 0x0000000fU]
24#define VM3           STATE[(state_i+M3) & 0x0000000fU]
25#define VRm1          STATE[(state_i+15) & 0x0000000fU]
26#define VRm2          STATE[(state_i+14) & 0x0000000fU]
27#define newV0         STATE[(state_i+15) & 0x0000000fU]
28#define newV1         STATE[state_i                 ]
29#define newVRm1       STATE[(state_i+14) & 0x0000000fU]
30
31#define FACT 2.32830643653869628906e-10
32
33static unsigned int state_i = 0;
34static unsigned int STATE[R];
35static unsigned int z0, z1, z2;
36
37void InitWELLRNG512a (unsigned int *init){
38   int j;
39   state_i = 0;
40   for (j = 0; j < R; j++)
41     STATE[j] = init[j];
42}
43
44double WELLRNG512a (void){
45  z0    = VRm1;
46  z1    = MAT0NEG (-16,V0)    ^ MAT0NEG (-15, VM1);
47  z2    = MAT0POS (11, VM2)  ;
48  newV1 = z1                  ^ z2; 
49  newV0 = MAT0NEG (-2,z0)     ^ MAT0NEG(-18,z1)    ^ MAT3NEG(-28,z2) ^ MAT4NEG(-5,0xda442d24U,newV1) ;
50  state_i = (state_i + 15) & 0x0000000fU;
51  return ((double) STATE[state_i]) * FACT;
52}
Note: See TracBrowser for help on using the repository browser.