~ubuntu-branches/ubuntu/quantal/commons-math/quantal

« back to all changes in this revision

Viewing changes to src/main/java/org/apache/commons/math/random/MersenneTwister.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2010-04-05 23:33:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100405233302-gpqlceked76nw28a
Tags: 2.1-1
* New upstream release.
* Bump Standards-Version to 3.8.4: no changes needed
* Bump debhelper to >= 7
* Switch to 3.0 (quilt) source format:
  - Remove B-D on quilt
  - Add d/source/format
  - Remove d/README.source

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 *   <li>Redistributions in binary form must reproduce the above copyright
54
54
 *       notice, this list of conditions and the following disclaimer in the
55
55
 *       documentation and/or other materials provided with the distribution.</li>
56
 
 *   <li>The names of its contributors may not be used to endorse or promote 
57
 
 *       products derived from this software without specific prior written 
 
56
 *   <li>The names of its contributors may not be used to endorse or promote
 
57
 *       products derived from this software without specific prior written
58
58
 *       permission.</li>
59
59
 * </ol></td></tr>
60
60
 
73
73
 * DAMAGE.</strong></td></tr>
74
74
 * </table>
75
75
 
76
 
 * @version $Revision: 797246 $ $Date: 2009-07-23 18:21:46 -0400 (Thu, 23 Jul 2009) $
 
76
 * @version $Revision: 902203 $ $Date: 2010-01-22 13:27:41 -0500 (Fri, 22 Jan 2010) $
77
77
 * @since 2.0
78
78
 
79
79
 */
136
136
     * generator built with the same seed.</p>
137
137
     * @param seed the initial seed (32 bits integer)
138
138
     */
 
139
    @Override
139
140
    public void setSeed(int seed) {
140
141
        // we use a long masked by 0xffffffffL as a poor man unsigned int
141
142
        long longMT = seed;
143
144
        for (mti = 1; mti < N; ++mti) {
144
145
            // See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier.
145
146
            // initializer from the 2002-01-09 C version by Makoto Matsumoto
146
 
            longMT = (1812433253l * (longMT ^ (longMT >> 30)) + mti) & 0xffffffffL; 
 
147
            longMT = (1812433253l * (longMT ^ (longMT >> 30)) + mti) & 0xffffffffL;
147
148
            mt[mti]= (int) longMT;
148
149
        }
149
150
    }
154
155
     * @param seed the initial seed (32 bits integers array), if null
155
156
     * the seed of the generator will be related to the current time
156
157
     */
 
158
    @Override
157
159
    public void setSeed(int[] seed) {
158
160
 
159
161
        if (seed == null) {
201
203
     * generator built with the same seed.</p>
202
204
     * @param seed the initial seed (64 bits integer)
203
205
     */
 
206
    @Override
204
207
    public void setSeed(long seed) {
205
208
        setSeed(new int[] { (int) (seed >>> 32), (int) (seed & 0xffffffffl) });
206
209
    }
214
217
     * @param bits number of random bits to produce
215
218
     * @return random bits generated
216
219
     */
 
220
    @Override
217
221
    protected int next(int bits) {
218
222
 
219
223
        int y;
241
245
        y = mt[mti++];
242
246
 
243
247
        // tempering
244
 
        y ^= (y >>> 11);
 
248
        y ^=  y >>> 11;
245
249
        y ^= (y <<   7) & 0x9d2c5680;
246
250
        y ^= (y <<  15) & 0xefc60000;
247
 
        y ^= (y >>> 18);
 
251
        y ^=  y >>> 18;
248
252
 
249
253
        return y >>> (32 - bits);
250
254