Mercurial > libavutil.hg
comparison random.c @ 636:c04808220c83 libavutil
spelling/grammar/consistency review part II
author | diego |
---|---|
date | Wed, 28 Jan 2009 23:03:17 +0000 |
parents | 8c48a1b999a3 |
children | 683a6dbdd2b2 |
comparison
equal
deleted
inserted
replaced
635:0a51400a64c9 | 636:c04808220c83 |
---|---|
1 /* | 1 /* |
2 * Mersenne Twister Random Algorithm | 2 * Mersenne Twister Random Algorithm |
3 * Copyright (c) 2006 Ryan Martell | 3 * Copyright (c) 2006 Ryan Martell |
4 * Based on A C-program for MT19937, with initialization improved 2002/1/26. Coded by | 4 * Based on a C program for MT19937, with initialization improved 2002/1/26. |
5 * Takuji Nishimura and Makoto Matsumoto. | 5 * Coded by Takuji Nishimura and Makoto Matsumoto. |
6 * | 6 * |
7 * This file is part of FFmpeg. | 7 * This file is part of FFmpeg. |
8 * | 8 * |
9 * FFmpeg is free software; you can redistribute it and/or | 9 * FFmpeg is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Lesser General Public | 10 * modify it under the terms of the GNU Lesser General Public |
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 */ | 22 */ |
23 | 23 |
24 | 24 |
25 /** | 25 /** |
26 see http://en.wikipedia.org/wiki/Mersenne_twister for an explanation of this algorithm. | 26 * See http://en.wikipedia.org/wiki/Mersenne_twister |
27 */ | 27 * for an explanation of this algorithm. |
28 */ | |
28 #include <stdio.h> | 29 #include <stdio.h> |
29 #include "random.h" | 30 #include "random.h" |
30 | 31 |
31 | 32 |
32 /* period parameters */ | 33 /* period parameters */ |
50 state->mt[0] = seed & 0xffffffff; | 51 state->mt[0] = seed & 0xffffffff; |
51 for (index = 1; index < AV_RANDOM_N; index++) { | 52 for (index = 1; index < AV_RANDOM_N; index++) { |
52 unsigned int prev= state->mt[index - 1]; | 53 unsigned int prev= state->mt[index - 1]; |
53 state->mt[index] = (1812433253UL * (prev ^ (prev>>30)) + index) & 0xffffffff; | 54 state->mt[index] = (1812433253UL * (prev ^ (prev>>30)) + index) & 0xffffffff; |
54 } | 55 } |
55 state->index= index; // will cause it to generate untempered numbers the first iteration | 56 state->index= index; // Will cause it to generate untempered numbers in the first iteration. |
56 } | 57 } |
57 | 58 |
58 #if LIBAVUTIL_VERSION_MAJOR < 50 | 59 #if LIBAVUTIL_VERSION_MAJOR < 50 |
59 void av_init_random(unsigned int seed, AVRandomState *state) | 60 void av_init_random(unsigned int seed, AVRandomState *state) |
60 { | 61 { |
61 av_random_init(state, seed); | 62 av_random_init(state, seed); |
62 } | 63 } |
63 #endif | 64 #endif |
64 | 65 |
65 /** generate AV_RANDOM_N words at one time (which will then be tempered later) (av_random calls this; you shouldn't) */ | 66 /** Generates AV_RANDOM_N words at one time (which will then be tempered later). |
67 * av_random calls this; you shouldn't. */ | |
66 void av_random_generate_untempered_numbers(AVRandomState *state) | 68 void av_random_generate_untempered_numbers(AVRandomState *state) |
67 { | 69 { |
68 int kk; | 70 int kk; |
69 unsigned int y; | 71 unsigned int y; |
70 | 72 |