# HG changeset patch # User michael # Date 1217459287 0 # Node ID 2862fa9da1102edfdffcbb54e9e9d95e5cc643de # Parent 5aa27a4a9e4578efe6e107e68a2d3f9382f9057f Add a multiplicative LFG for those thinking the additive is not good enough, just 4 lines of code. diff -r 5aa27a4a9e45 -r 2862fa9da110 lfg.h --- a/lfg.h Wed Jul 30 12:02:22 2008 +0000 +++ b/lfg.h Wed Jul 30 23:08:07 2008 +0000 @@ -30,7 +30,7 @@ void av_lfg_init(AVLFG *c, unsigned int seed); /** - * Gets the next random unsigned 32bit number. + * Gets the next random unsigned 32bit number using a ALFG. * * Please also consider a simple LCG like state= state*1664525+1013904223, * it may be good enough and faster for your specific use case. @@ -40,4 +40,15 @@ return c->state[c->index++ & 63]; } +/** + * Gets the next random unsigned 32bit number using a MLFG. + * + * Please also consider the av_lfg_get() above, it is faster. + */ +static inline unsigned int av_mlfg_get(AVLFG *c){ + unsigned int a= c->state[(c->index-55) & 63]; + unsigned int b= c->state[(c->index-24) & 63]; + return c->state[c->index++ & 63] = a*b+a+b; +} + #endif //FFMPEG_LFG_H