[xiph-commits] r17680 - trunk/squishyball

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Mon Nov 29 07:23:14 PST 2010


Author: xiphmont
Date: 2010-11-29 07:23:14 -0800 (Mon, 29 Nov 2010)
New Revision: 17680

Modified:
   trunk/squishyball/main.c
Log:
Make rand() safe for non-Linux


Modified: trunk/squishyball/main.c
===================================================================
--- trunk/squishyball/main.c	2010-11-29 14:43:55 UTC (rev 17679)
+++ trunk/squishyball/main.c	2010-11-29 15:23:14 UTC (rev 17680)
@@ -177,24 +177,27 @@
   return 0;
 }
 
+int randrange(int range){
+  return (int)floor(range * rand()/(RAND_MAX+1.0));
+}
+
 void randomize_samples(int *r,int *cchoice, int test_mode){
   switch(test_mode){
   case 1:
     r[0] = 0;
     r[1] = 1;
-    r[2] = random()&1;
+    r[2] = randrange(2);
     *cchoice = (r[1]==r[2] ? 1 : 0);
     break;
   case 0:
-    r[0] = random()&1;
+    r[0] = randrange(2);
     r[1] = 1-r[0];
     *cchoice = 1;
     break;
   case 2:
     r[0] = r[1] = r[2] = 0;
-    r[random()%3] = 1;
-    if (random()&1)
-    {
+    r[randrange(3)] = 1;
+    if (randrange(2)){
       r[0] = 1-r[0];
       r[1] = 1-r[1];
       r[2] = 1-r[2];



More information about the commits mailing list