changeset 9199:ea0e5e9a520f libavcodec

Replace random() usage in test programs by av_lfg_*().
author diego
date Fri, 20 Mar 2009 11:48:27 +0000
parents 342e95d4784b
children 7b62de9c383d
files cabac.c dct-test.c fft-test.c motion-test.c rangecoder.c snow.c
diffstat 6 files changed, 44 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/cabac.c	Fri Mar 20 11:43:58 2009 +0000
+++ b/cabac.c	Fri Mar 20 11:48:27 2009 +0000
@@ -179,9 +179,9 @@
 }
 
 #ifdef TEST
-#undef random
 #define SIZE 10240
 
+#include "libavutil/lfg.h"
 #include "avcodec.h"
 #include "cabac.h"
 
@@ -191,12 +191,14 @@
     uint8_t r[9*SIZE];
     int i;
     uint8_t state[10]= {0};
+    AVLFG prn;
 
+    av_lfg_init(&prn, 1);
     ff_init_cabac_encoder(&c, b, SIZE);
     ff_init_cabac_states(&c);
 
     for(i=0; i<SIZE; i++){
-        r[i]= random()%7;
+        r[i] = av_lfg_get(&prn) % 7;
     }
 
     for(i=0; i<SIZE; i++){
--- a/dct-test.c	Fri Mar 20 11:43:58 2009 +0000
+++ b/dct-test.c	Fri Mar 20 11:48:27 2009 +0000
@@ -33,6 +33,7 @@
 #include <math.h>
 
 #include "libavutil/common.h"
+#include "libavutil/lfg.h"
 
 #include "simple_idct.h"
 #include "aandcttab.h"
@@ -41,7 +42,6 @@
 #include "x86/idct_xvid.h"
 
 #undef printf
-#undef random
 
 void *fast_memcpy(void *a, const void *b, size_t c){return memcpy(a,b,c);};
 
@@ -208,8 +208,9 @@
     int64_t sysErr[64], sysErrMax=0;
     int maxout=0;
     int blockSumErrMax=0, blockSumErr;
+    AVLFG prn;
 
-    srandom(0);
+    av_lfg_init(&prn, 1);
 
     err_inf = 0;
     err2 = 0;
@@ -220,7 +221,7 @@
         switch(test){
         case 0:
             for(i=0;i<64;i++)
-                block1[i] = (random() % 512) -256;
+                block1[i] = (av_lfg_get(&prn) % 512) -256;
             if (is_idct){
                 fdct(block1);
 
@@ -229,12 +230,12 @@
             }
         break;
         case 1:{
-            int num= (random()%10)+1;
+            int num = av_lfg_get(&prn) % 10 + 1;
             for(i=0;i<num;i++)
-                block1[random()%64] = (random() % 512) -256;
+                block1[av_lfg_get(&prn) % 64] = av_lfg_get(&prn) % 512 -256;
         }break;
         case 2:
-            block1[0]= (random()%4096)-2048;
+            block1[0] = av_lfg_get(&prn) % 4096 - 2048;
             block1[63]= (block1[0]&1)^1;
         break;
         }
@@ -334,7 +335,7 @@
     switch(test){
     case 0:
         for(i=0;i<64;i++)
-            block1[i] = (random() % 512) -256;
+            block1[i] = av_lfg_get(&prn) % 512 -256;
         if (is_idct){
             fdct(block1);
 
@@ -344,10 +345,10 @@
     break;
     case 1:{
     case 2:
-        block1[0] = (random() % 512) -256;
-        block1[1] = (random() % 512) -256;
-        block1[2] = (random() % 512) -256;
-        block1[3] = (random() % 512) -256;
+        block1[0] = av_lfg_get(&prn) % 512 -256;
+        block1[1] = av_lfg_get(&prn) % 512 -256;
+        block1[2] = av_lfg_get(&prn) % 512 -256;
+        block1[3] = av_lfg_get(&prn) % 512 -256;
     }break;
     }
 
@@ -471,7 +472,9 @@
 {
     int it, i, it1, ti, ti1, err_max, v;
 
-    srandom(0);
+    AVLFG prn;
+
+    av_lfg_init(&prn, 1);
 
     /* just one test to see if code is correct (precision is less
        important here) */
@@ -480,7 +483,7 @@
 
         /* XXX: use forward transform to generate values */
         for(i=0;i<64;i++)
-            block1[i] = (random() % 256) - 128;
+            block1[i] = av_lfg_get(&prn) % 256 - 128;
         block1[0] += 1024;
 
         for(i=0; i<64; i++)
--- a/fft-test.c	Fri Mar 20 11:43:58 2009 +0000
+++ b/fft-test.c	Fri Mar 20 11:48:27 2009 +0000
@@ -23,6 +23,7 @@
  * FFT and MDCT tests.
  */
 
+#include "libavutil/lfg.h"
 #include "dsputil.h"
 #include <math.h>
 #include <unistd.h>
@@ -31,7 +32,6 @@
 #include <string.h>
 
 #undef exit
-#undef random
 
 /* reference fft */
 
@@ -131,7 +131,9 @@
 
 float frandom(void)
 {
-    return (float)((random() & 0xffff) - 32768) / 32768.0;
+    AVLFG prn;
+    av_lfg_init(&prn, 1);
+    return (float)((av_lfg_get(&prn) & 0xffff) - 32768) / 32768.0;
 }
 
 int64_t gettime(void)
--- a/motion-test.c	Fri Mar 20 11:43:58 2009 +0000
+++ b/motion-test.c	Fri Mar 20 11:48:27 2009 +0000
@@ -30,10 +30,10 @@
 #include <unistd.h>
 
 #include "dsputil.h"
+#include "libavutil/lfg.h"
 
 #undef exit
 #undef printf
-#undef random
 
 #define WIDTH 64
 #define HEIGHT 64
@@ -44,9 +44,12 @@
 void fill_random(uint8_t *tab, int size)
 {
     int i;
+    AVLFG prn;
+
+    av_lfg_init(&prn, 1);
     for(i=0;i<size;i++) {
 #if 1
-        tab[i] = random() % 256;
+        tab[i] = av_lfg_get(&prn) % 256;
 #else
         tab[i] = i;
 #endif
@@ -142,7 +145,7 @@
     ctx = avcodec_alloc_context();
     ctx->dsp_mask = FF_MM_FORCE;
     dsputil_init(&cctx, ctx);
-    for (c = 0; c < 2; c++) {
+    for (c = 0; c < 1; c++) {
         int x;
         ctx->dsp_mask = FF_MM_FORCE | flags[c];
         dsputil_init(&mmxctx, ctx);
--- a/rangecoder.c	Fri Mar 20 11:43:58 2009 +0000
+++ b/rangecoder.c	Fri Mar 20 11:48:27 2009 +0000
@@ -111,13 +111,18 @@
 
 #ifdef TEST
 #define SIZE 10240
-#undef random
+
+#include "libavutil/lfg.h"
+
 int main(void){
     RangeCoder c;
     uint8_t b[9*SIZE];
     uint8_t r[9*SIZE];
     int i;
     uint8_t state[10]= {0};
+    AVLFG prn;
+
+    av_lfg_init(&prn, 1);
 
     ff_init_range_encoder(&c, b, SIZE);
     ff_build_rac_states(&c, 0.05*(1LL<<32), 128+64+32+16);
@@ -125,7 +130,7 @@
     memset(state, 128, sizeof(state));
 
     for(i=0; i<SIZE; i++){
-        r[i]= random()%7;
+        r[i] = av_lfg_get(&prn) % 7;
     }
 
     for(i=0; i<SIZE; i++){
--- a/snow.c	Fri Mar 20 11:43:58 2009 +0000
+++ b/snow.c	Fri Mar 20 11:48:27 2009 +0000
@@ -4689,7 +4689,8 @@
 #undef malloc
 #undef free
 #undef printf
-#undef random
+
+#include "libavutil/lfg.h"
 
 int main(void){
     int width=256;
@@ -4699,10 +4700,13 @@
     int i;
     s.spatial_decomposition_count=6;
     s.spatial_decomposition_type=1;
+    AVLFG prn;
+
+    av_lfg_init(&prn, 1);
 
     printf("testing 5/3 DWT\n");
     for(i=0; i<width*height; i++)
-        buffer[0][i]= buffer[1][i]= random()%54321 - 12345;
+        buffer[0][i] = buffer[1][i] = av_lfg_get(&prn) % 54321 - 12345;
 
     ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
     ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
@@ -4713,7 +4717,7 @@
     printf("testing 9/7 DWT\n");
     s.spatial_decomposition_type=0;
     for(i=0; i<width*height; i++)
-        buffer[0][i]= buffer[1][i]= random()%54321 - 12345;
+        buffer[0][i] = buffer[1][i] = av_lfg_get(&prn) % 54321 - 12345;
 
     ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
     ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);