aboutsummaryrefslogtreecommitdiff
path: root/shared/common/rand.c
diff options
context:
space:
mode:
authorN.N. <krzyszcz@users.sourceforge.net>2004-04-20 13:55:28 +0000
committerN.N. <krzyszcz@users.sourceforge.net>2004-04-20 13:55:28 +0000
commit6b30948a86211b4c8ca209d3025cd062f9366e3c (patch)
tree3fe120394de95b4a5c51903452f8f933b6f8524c /shared/common/rand.c
parenta79ea60bfc5f20b37f1410fc589167c15f83cd1a (diff)
importing tables
svn path=/trunk/externals/miXed/; revision=1619
Diffstat (limited to 'shared/common/rand.c')
-rw-r--r--shared/common/rand.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/shared/common/rand.c b/shared/common/rand.c
index 37dcf62..7a3fff4 100644
--- a/shared/common/rand.c
+++ b/shared/common/rand.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997-2003 Miller Puckette, krzYszcz, and others.
+/* Copyright (c) 1997-2004 Miller Puckette, krzYszcz, and others.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
@@ -51,11 +51,19 @@ int rand_int(unsigned int *statep, int range)
return (result < range ? result : range - 1);
}
+float rand_unipolar(unsigned int *statep)
+{
+ float result;
+ *statep = *statep * 472940017 + 832416023;
+ result = (float)((double)*statep * (1./4294967296.));
+ return (result);
+}
+
/* borrowed from d_osc.c, LATER rethink */
-float rand_float(unsigned int *statep)
+float rand_bipolar(unsigned int *statep)
{
- float result = ((float)((*statep & 0x7fffffff) - 0x40000000))
+ float result = ((float)(((int)*statep & 0x7fffffff) - 0x40000000))
* (float)(1.0 / 0x40000000);
- *statep = *statep * 435898247 + 382842987;
+ *statep = (unsigned)((int)*statep * 435898247 + 382842987);
return (result);
}