[Ffmpeg-devel] [RFC] av_random...

Ryan Martell rdm4
Sat Jan 6 02:56:41 CET 2007


I need to have a random for generating a GUID for mms streaming, and  
there also needs to be one for AC3 (right?).  Michael suggested
"a LFG or mersenne twister based av_random() for libavutil would  
certainly be welcome"

I have tweaked some example source code, and have sent an email  
asking the author if he would allow it for inclusion; if not, I'll  
rewrite it based on the published formula.

Does this an interface work for you:

#define AV_RANDOM_PERIOD 624

typedef struct {
     unsigned int magic_cookie; ///< prevent someone from calling  
random without the state setup (sets it up automatically)
     unsigned long mt[AV_RANDOM_PERIOD];	///< the array for the state  
     int mti;
} AVRandomState;

void av_init_random(unsigned long seed, AVRandomState *state);

unsigned long av_random(AVRandomState *state); // 32 bit random
double av_random_real1(AVRandomState *state); // [0-1] as double

Or would you rather have:

AVRandomState *av_init_random(unsigned long seed);
void av_free_random(AVRandomState *state);

unsigned long av_random(AVRandomState *state);

Or something else?

I am passing in the state for thread safety; if that's not a concern,  
we could make it static.


More information about the ffmpeg-devel mailing list