diff options
author | Diego Biurrun <diego@biurrun.de> | 2009-03-20 11:48:27 +0000 |
---|---|---|
committer | Diego Biurrun <diego@biurrun.de> | 2009-03-20 11:48:27 +0000 |
commit | 294eaa26437edf29d866b0bf63d7de57515a0f95 (patch) | |
tree | 605c390daa352a0400dae8422e65af9487f122c4 /libavutil | |
parent | c7594e0764d9d41ec4fb6b14deacd3cc6eafc4b3 (diff) | |
download | ffmpeg-294eaa26437edf29d866b0bf63d7de57515a0f95.tar.gz |
Replace random() usage in test programs by av_lfg_*().
Originally committed as revision 18070 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/aes.c | 7 | ||||
-rw-r--r-- | libavutil/pca.c | 13 | ||||
-rw-r--r-- | libavutil/tree.c | 11 |
3 files changed, 20 insertions, 11 deletions
diff --git a/libavutil/aes.c b/libavutil/aes.c index 26bc43fc5d..49c23e1d46 100644 --- a/libavutil/aes.c +++ b/libavutil/aes.c @@ -192,10 +192,9 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) { } #ifdef TEST +#include "lfg.h" #include "log.h" -#undef random - int main(void){ int i,j; AVAES ae, ad, b; @@ -209,10 +208,12 @@ int main(void){ {0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7, 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf}, {0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65}}; uint8_t temp[16]; + AVLFG prn; av_aes_init(&ae, "PI=3.141592654..", 128, 0); av_aes_init(&ad, "PI=3.141592654..", 128, 1); av_log_set_level(AV_LOG_DEBUG); + av_lfg_init(&prn, 1); for(i=0; i<2; i++){ av_aes_init(&b, rkey[i], 128, 1); @@ -224,7 +225,7 @@ int main(void){ for(i=0; i<10000; i++){ for(j=0; j<16; j++){ - pt[j]= random(); + pt[j] = av_lfg_get(&prn); } {START_TIMER av_aes_crypt(&ae, temp, pt, 1, NULL, 0); diff --git a/libavutil/pca.c b/libavutil/pca.c index f803d3b677..09c542bf93 100644 --- a/libavutil/pca.c +++ b/libavutil/pca.c @@ -164,9 +164,9 @@ int ff_pca(PCA *pca, double *eigenvector, double *eigenvalue){ #ifdef TEST #undef printf -#undef random #include <stdio.h> #include <stdlib.h> +#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; j<LEN; j++){ v[j] -= v[pos]; }*/ -// sum += random()%10; +// sum += av_lfg_get(&prn) % 10; /* for(j=0; j<LEN; j++){ v[j] -= sum/LEN; }*/ diff --git a/libavutil/tree.c b/libavutil/tree.c index c9a19fa37d..62437ffd5b 100644 --- a/libavutil/tree.c +++ b/libavutil/tree.c @@ -144,7 +144,9 @@ void av_tree_enumerate(AVTreeNode *t, void *opaque, int (*f)(void *opaque, void #endif #ifdef TEST -#undef random + +#include "lfg.h" + static int check(AVTreeNode *t){ if(t){ int left= check(t->child[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); |