From 294eaa26437edf29d866b0bf63d7de57515a0f95 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Fri, 20 Mar 2009 11:48:27 +0000 Subject: [PATCH] Replace random() usage in test programs by av_lfg_*(). Originally committed as revision 18070 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/cabac.c | 6 ++++-- libavcodec/dct-test.c | 29 ++++++++++++++++------------- libavcodec/fft-test.c | 6 ++++-- libavcodec/motion-test.c | 9 ++++++--- libavcodec/rangecoder.c | 9 +++++++-- libavcodec/snow.c | 10 +++++++--- libavutil/aes.c | 7 ++++--- libavutil/pca.c | 13 ++++++++----- libavutil/tree.c | 11 ++++++++--- 9 files changed, 64 insertions(+), 36 deletions(-) diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c index c2a7f8a1e5..c3b3429764 100644 --- a/libavcodec/cabac.c +++ b/libavcodec/cabac.c @@ -179,9 +179,9 @@ void ff_init_cabac_states(CABACContext *c){ } #ifdef TEST -#undef random #define SIZE 10240 +#include "libavutil/lfg.h" #include "avcodec.h" #include "cabac.h" @@ -191,12 +191,14 @@ int main(void){ 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 #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 @@ void dct_error(const char *name, int is_idct, 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 @@ void dct_error(const char *name, int is_idct, 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 @@ void dct_error(const char *name, int is_idct, } break; case 1:{ - int num= (random()%10)+1; + int num = av_lfg_get(&prn) % 10 + 1; for(i=0;i #include @@ -31,7 +32,6 @@ #include #undef exit -#undef random /* reference fft */ @@ -131,7 +131,9 @@ void mdct_ref(float *output, float *input, int nbits) 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) diff --git a/libavcodec/motion-test.c b/libavcodec/motion-test.c index 38f59946a8..90f0a2e1bc 100644 --- a/libavcodec/motion-test.c +++ b/libavcodec/motion-test.c @@ -30,10 +30,10 @@ #include #include "dsputil.h" +#include "libavutil/lfg.h" #undef exit #undef printf -#undef random #define WIDTH 64 #define HEIGHT 64 @@ -44,9 +44,12 @@ uint8_t img2[WIDTH * HEIGHT]; void fill_random(uint8_t *tab, int size) { int i; + AVLFG prn; + + av_lfg_init(&prn, 1); for(i=0;idsp_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); diff --git a/libavcodec/rangecoder.c b/libavcodec/rangecoder.c index 3c3220da27..c9848e8875 100644 --- a/libavcodec/rangecoder.c +++ b/libavcodec/rangecoder.c @@ -111,13 +111,18 @@ int ff_rac_terminate(RangeCoder *c){ #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 @@ int main(void){ memset(state, 128, sizeof(state)); for(i=0; i #include +#include "lfg.h" int main(void){ PCA *pca; @@ -174,15 +174,18 @@ int main(void){ #define LEN 8 double eigenvector[LEN*LEN]; double eigenvalue[LEN]; + AVLFG prn; + + av_lfg_init(&prn, 1); pca= ff_pca_init(LEN); for(i=0; i<9000000; i++){ double v[2*LEN+100]; double sum=0; - int pos= random()%LEN; - int v2= (random()%101) - 50; - v[0]= (random()%101) - 50; + int pos = av_lfg_get(&prn) % LEN; + int v2 = av_lfg_get(&prn) % 101 - 50; + v[0] = av_lfg_get(&prn) % 101 - 50; for(j=1; j<8; j++){ if(j<=pos) v[j]= v[0]; else v[j]= v2; @@ -191,7 +194,7 @@ int main(void){ /* for(j=0; jchild[0]); @@ -179,9 +181,12 @@ int cmp(const void *a, const void *b){ int main(void){ int i,k; AVTreeNode *root= NULL, *node=NULL; + AVLFG prn; + + av_lfg_init(&prn, 1); for(i=0; i<10000; i++){ - int j= (random()%86294); + int j = av_lfg_get(&prn) % 86294; if(check(root) > 999){ av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); print(root, 0); @@ -192,7 +197,7 @@ int main(void){ node= av_mallocz(av_tree_node_size); av_tree_insert(&root, (void*)(j+1), cmp, &node); - j= (random()%86294); + j = av_lfg_get(&prn) % 86294; { AVTreeNode *node2=NULL; av_log(NULL, AV_LOG_ERROR, "removing %4d\n", j);