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

Michael Niedermayer michaelni
Sat Jan 6 12:42:25 CET 2007


On Fri, Jan 05, 2007 at 07:56:41PM -0600, Ryan Martell wrote:
> Hi--
> 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

i dont like that name at all, as its not the period of the generator
maybe simply AV_RANDOM_N would do or maybe calling it 
degree of recurrence like wikipedia does ...

> 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 
> vector
>     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);

this is closer to what i had in mind ...

though i would like av_random() to be in a header file and be static inline
as its likely called often, the function is pretty small and speed might

also long -> int, POSIX gurantees that int is >=32bit
and avoid (u)int32_t in the code as it might be slow on some obscure

Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Let us carefully observe those good qualities wherein our enemies excel us
and endeavor to excel them, by avoiding what is faulty, and imitating what
is excellent in them. -- Plutarch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070106/53d1bd1d/attachment.pgp>

More information about the ffmpeg-devel mailing list