Go to the source code of this file.
Data Structures | |
| struct | AVRandomState |
Defines | |
| #define | AV_RANDOM_N 624 |
Functions | |
| void | av_init_random (unsigned int 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). | |
| static unsigned int | av_random (AVRandomState *state) |
| static double | av_random_real1 (AVRandomState *state) |
| void | av_benchmark_random (void) |
| #define AV_RANDOM_N 624 |
Definition at line 27 of file random.h.
Referenced by av_init_random(), av_random(), and av_random_generate_untempered_numbers().
| void av_benchmark_random | ( | void | ) |
| void av_init_random | ( | unsigned int | 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
initializes mt[AV_RANDOM_N] with a seed
Definition at line 46 of file random.c.
References AV_RANDOM_N, AVRandomState::index, and AVRandomState::mt.
Referenced by ac3_decode_init(), cook_decode_init(), decode_init(), main(), mpc7_decode_init(), mpc8_decode_init(), and roq_encode_init().
00047 { 00048 int index; 00049 00050 /* 00051 This differs from the wikipedia article. Source is from the Makoto 00052 Makoto Matsumoto and Takuji Nishimura code, with the following comment: 00053 */ 00054 /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ 00055 /* In the previous versions, MSBs of the seed affect */ 00056 /* only MSBs of the array mt[]. */ 00057 state->mt[0] = seed & 0xffffffff; 00058 for (index = 1; index < AV_RANDOM_N; index++) { 00059 unsigned int prev= state->mt[index - 1]; 00060 state->mt[index] = (1812433253UL * (prev ^ (prev>>30)) + index) & 0xffffffff; 00061 } 00062 state->index= index; // will cause it to generate untempered numbers the first iteration 00063 }
| static unsigned int av_random | ( | AVRandomState * | state | ) | [inline, static] |
generates a random number on [0,0xffffffff]-interval
Definition at line 39 of file random.h.
References av_random_generate_untempered_numbers(), AV_RANDOM_N, and AVRandomState::index.
Referenced by av_random_real1(), get_high_utility_cell(), get_transform_coeffs_ch(), http_parse_request(), idx_to_quant(), nelly_decode_block(), scalar_dequant_float(), and start_multicast().
00040 { 00041 unsigned int y; 00042 00043 // regenerate the untempered numbers if we should... 00044 if (state->index >= AV_RANDOM_N) 00045 av_random_generate_untempered_numbers(state); 00046 00047 // grab one... 00048 y = state->mt[state->index++]; 00049 00050 /* Now temper (Mersenne Twister coefficients) The coefficients for MT19937 are.. */ 00051 y ^= (y >> 11); 00052 y ^= (y << 7) & 0x9d2c5680; 00053 y ^= (y << 15) & 0xefc60000; 00054 y ^= (y >> 18); 00055 00056 return y; 00057 }
| void av_random_generate_untempered_numbers | ( | AVRandomState * | state | ) |
Regenerate the untempered numbers (must be done every 624 iterations, or it will loop).
generate AV_RANDOM_N words at one time (which will then be tempered later) (av_random calls this; you shouldn't)
Definition at line 66 of file random.c.
References A, AV_RANDOM_N, AVRandomState::index, LOWER_MASK, M, AVRandomState::mt, and UPPER_MASK.
Referenced by av_random().
00067 { 00068 int kk; 00069 unsigned int y; 00070 00071 for (kk = 0; kk < AV_RANDOM_N - M; kk++) { 00072 y = (state->mt[kk] & UPPER_MASK) | (state->mt[kk + 1] & LOWER_MASK); 00073 state->mt[kk] = state->mt[kk + M] ^ (y >> 1) ^ ((y&1)*A); 00074 } 00075 for (; kk < AV_RANDOM_N - 1; kk++) { 00076 y = (state->mt[kk] & UPPER_MASK) | (state->mt[kk + 1] & LOWER_MASK); 00077 state->mt[kk] = state->mt[kk + (M - AV_RANDOM_N)] ^ (y >> 1) ^ ((y&1)*A); 00078 } 00079 y = (state->mt[AV_RANDOM_N - 1] & UPPER_MASK) | (state->mt[0] & LOWER_MASK); 00080 state->mt[AV_RANDOM_N - 1] = state->mt[M - 1] ^ (y >> 1) ^ ((y&1)*A); 00081 state->index = 0; 00082 }
| static double av_random_real1 | ( | AVRandomState * | state | ) | [inline, static] |
return random in range [0-1] as double
Definition at line 60 of file random.h.
References av_random().
00061 { 00062 /* divided by 2^32-1 */ 00063 return av_random(state) * (1.0 / 4294967296.0); 00064 }
1.5.1