Browse code

Make trasher use a well defined random number generator and allow the seed to be specified on the cmd line.

Originally committed as revision 22228 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2010/03/06 10:31:17
Showing 1 changed files
... ...
@@ -24,13 +24,18 @@
24 24
 #include <time.h>
25 25
 #include <inttypes.h>
26 26
 
27
+static uint32_t state;
28
+static uint32_t ran(void){
29
+    return state= state*1664525+1013904223;
30
+}
31
+
27 32
 int main(int argc, char** argv)
28 33
 {
29 34
     FILE *f;
30 35
     int count, maxburst, length;
31 36
 
32
-    if (argc < 4){
33
-        printf("USAGE: trasher <filename> <count> <maxburst>\n");
37
+    if (argc < 5){
38
+        printf("USAGE: trasher <filename> <count> <maxburst> <seed>\n");
34 39
         return 1;
35 40
     }
36 41
 
... ...
@@ -41,16 +46,15 @@ int main(int argc, char** argv)
41 41
     }
42 42
     count= atoi(argv[2]);
43 43
     maxburst= atoi(argv[3]);
44
-
45
-    srandom (time (0));
44
+    state= atoi(argv[4]);
46 45
 
47 46
     fseek(f, 0, SEEK_END);
48 47
     length= ftell(f);
49 48
     fseek(f, 0, SEEK_SET);
50 49
 
51 50
     while(count--){
52
-        int burst= 1 + random() * (uint64_t) (abs(maxburst)-1) / RAND_MAX;
53
-        int pos= random() * (uint64_t) length / RAND_MAX;
51
+        int burst= 1 + ran() * (uint64_t) (abs(maxburst)-1) / UINT32_MAX;
52
+        int pos= ran() * (uint64_t) length / UINT32_MAX;
54 53
         fseek(f, pos, SEEK_SET);
55 54
 
56 55
         if(maxburst<0) burst= -maxburst;
... ...
@@ -59,7 +63,7 @@ int main(int argc, char** argv)
59 59
             continue;
60 60
 
61 61
         while(burst--){
62
-            int val= random() * 256ULL / RAND_MAX;
62
+            int val= ran() * 256ULL / UINT32_MAX;
63 63
 
64 64
             if(maxburst<0) val=0;
65 65