aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2008-07-30 23:08:07 +0000
committerMichael Niedermayer <michaelni@gmx.at>2008-07-30 23:08:07 +0000
commit310d442456881e448d22afa9d8b1a8687b5dd2bf (patch)
tree9ef4880d45f038a1d1a9909d7dbd093b86c634bb
parent62f2523062c022c511eccff88a0dc2cf9e62a70a (diff)
downloadffmpeg-310d442456881e448d22afa9d8b1a8687b5dd2bf.tar.gz
Add a multiplicative LFG for those thinking the additive is not good
enough, just 4 lines of code. Originally committed as revision 14478 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavutil/lfg.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/libavutil/lfg.h b/libavutil/lfg.h
index 36c36f446b..3d3f9332ab 100644
--- a/libavutil/lfg.h
+++ b/libavutil/lfg.h
@@ -30,7 +30,7 @@ typedef struct {
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 @@ static inline unsigned int av_lfg_get(AVLFG *c){
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