diff options
Diffstat (limited to 'reference/C/CONTRIB/SNIP/rand2.c')
-rwxr-xr-x | reference/C/CONTRIB/SNIP/rand2.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/reference/C/CONTRIB/SNIP/rand2.c b/reference/C/CONTRIB/SNIP/rand2.c new file mode 100755 index 0000000..9759671 --- /dev/null +++ b/reference/C/CONTRIB/SNIP/rand2.c @@ -0,0 +1,51 @@ +/********************************************************************
+ The McGill Super-Duper Random Number Generator
+ G. Marsaglia, K. Ananthanarayana, N. Paul
+
+ Incorporating the Ziggurat method of sampling from decreasing
+ or symmetric unimodal density functions.
+ G. Marsaglia, W.W. Tsang
+
+ Rewritten into C by E. Schneider
+ *********************************************************************/
+
+static unsigned long mcgn, srgn;
+
+#define MULT 69069L
+
+void rstart (long i1, long i2)
+{
+ mcgn = (unsigned long)((i1 == 0L) ? 0L : i1 | 1L);
+ srgn = (unsigned long)((i2 == 0L) ? 0L : (i2 & 0x7FFL) | 1L);
+}
+
+long uni(void)
+{
+ unsigned long r0, r1;
+
+ r0 = (srgn >> 15);
+ r1 = srgn ^ r0;
+ r0 = (r1 << 17);
+ srgn = r0 ^ r1;
+ mcgn = MULT * mcgn;
+ r1 = mcgn ^ srgn;
+ return (r1 >> 1);
+}
+
+long vni(void)
+{
+ unsigned long r0, r1;
+
+ r0 = (srgn >> 15);
+ r1 = srgn ^ r0;
+ r0 = (r1 << 17);
+ srgn = r0 ^ r1;
+ mcgn = MULT * mcgn;
+ r1 = mcgn ^ srgn;
+ return r1;
+}
+
+/*
+"Anyone who consider arithmetic means of producing random number is,
+ of course, in a state of sin" - John Von Neumann
+*/
|