]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Add a multiplicative LFG for thouse thinking the additative isnt good
authormichael <michael@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Wed, 30 Jul 2008 23:08:07 +0000 (23:08 +0000)
committermichael <michael@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Wed, 30 Jul 2008 23:08:07 +0000 (23:08 +0000)
enough, just 4 lines of code.

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@14478 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

libavutil/lfg.h

index 36c36f446b5135f7e552ad61ce7d380cfed57d2a..3d3f9332abfd6a72cb5e183845d967a14c7ca5f1 100644 (file)
@@ -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