Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Trying to implement the C++ minstd_rand0 to get quick portability
[simgrid.git] / teshsuite / surf / maxmin_bench / maxmin_bench.c
index 99f393e..163dfd4 100644 (file)
 #include "xbt/xbt_os_time.h"
 #include "xbt/sysdep.h"         /* time manipulation for benchmarking */
 
+#define MYRANDMAX 1000
+
 #include <stdlib.h>
 #include <stdio.h>
 
 double date;
+unsigned long seedx= 0;
+
+int myrand();
+inline int myrand() {
+  seedx=seedx * 16807 % 2147483647;
+  return seedx%1000;
+}
 
 double float_random(double max);
 double float_random(double max)
 {
-  return ((max * rand()) / (RAND_MAX + 1.0));
+  return ((max * myrand()) / (MYRANDMAX + 1.0));
 }
 
 int int_random(int max);
 int int_random(int max)
 {
-  return (int) (((max * 1.0) * rand()) / (RAND_MAX + 1.0));
+  return (int) (((max * 1.0) * myrand()) / (MYRANDMAX + 1.0));
 }
 
 void test(int nb_cnst, int nb_var, int nb_elem, int pw_base_limit, int pw_max_limit, float rate_no_limit, int max_share, int mode);
@@ -72,7 +81,7 @@ void test(int nb_cnst, int nb_var, int nb_elem, int pw_base_limit, int pw_max_li
     }
   }
 
-  printf("Starting to solve(%i,%i,%i)\n",rand()%1000,rand()%1000,rand()%1000);
+  printf("Starting to solve(%i,%i,%i)\n",myrand()%1000,myrand()%1000,myrand()%1000);
   date = xbt_os_time() * 1000000;
   lmm_solve(Sys);
   date = xbt_os_time() * 1000000 - date;
@@ -145,8 +154,6 @@ int main(int argc, char **argv)
   //How many times?
   testcount=atoi(argv[2]);
   
-  srand(testcount);
-
   //Show me everything (debug or performance)!
   mode=0;
   if(argc>=4 && strcmp(argv[3],"test")==0)
@@ -178,6 +185,8 @@ int main(int argc, char **argv)
   xbt_init(&argc, argv);
   
   for(i=0;i<testcount;i++){
+    seedx=i+1;
+    printf("Starting %i: (%i,%i,%i)\n",i,myrand()%1000,myrand()%1000,myrand()%1000);
     test(nb_cnst, nb_var, nb_elem, pw_base_limit, pw_max_limit, rate_no_limit,max_share,mode);
     acc_date+=date;
     acc_date2+=date*date;