From 6b30948a86211b4c8ca209d3025cd062f9366e3c Mon Sep 17 00:00:00 2001 From: "N.N." Date: Tue, 20 Apr 2004 13:55:28 +0000 Subject: importing tables svn path=/trunk/externals/miXed/; revision=1619 --- shared/common/rand.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'shared/common/rand.c') 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); } -- cgit v1.2.1