[Ffmpeg-devel] [RFC] av_random...
Michael Niedermayer
michaelni
Mon Jan 8 17:00:26 CET 2007
Hi
On Sun, Jan 07, 2007 at 08:08:01PM -0600, Ryan Martell wrote:
[...]
> >>
> >>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 ...
>
> Well, this doesn't make as much sense with the random being inlined,
> since the AVRandomState would have to be visible for the inlining to
> work. In my mind, it would make sense for it to use a malloc/free if
> the structure was opaque (in the c file), but not if it's in the h file.
ok
[...]
> #define AV_RANDOM_N 624
> #define AV_RANDOM_MAGIC_COOKIE 0xdeadbeef
>
> typedef struct {
> unsigned int magic_cookie; ///< prevent someone from calling random without the state setup
i dont like these magic_cookies, if someone calls the code without init then
thats pretty much his problem IMHO
> unsigned long mt[AV_RANDOM_N]; ///< the array for the state vector
unsigned int or uint_fast32_t if you want to be pedantic but long is
64-bit on some architectures and that is not really wanted here i think
> int mti; ///< current untempered value we use as the base.
> } AVRandomState;
>
>
> void av_init_random(unsigned long seed, AVRandomState *state); ///< to be inlined, the struct must be visible, so it doesn't make sense to try and keep it opaque with malloc/free like calls
> void av_random_generate_untempered_numbers(AVRandomState *state); ///< Regenerate the untempered numbers (must be done every 624 iterations, or it will loop)
>
> /* generates a random number on [0,0xffffffff]-interval */
> static inline unsigned int av_random(AVRandomState *state)
that should be /** ... */ for doxygen compatibility
> {
> unsigned int y= 0;
y is not read before its written so the =0 is redundant
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Everything should be made as simple as possible, but not simpler.
-- Albert Einstein
-------------- 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/20070108/97c47e4c/attachment.pgp>
More information about the ffmpeg-devel
mailing list