/* 2004/12/10 REMIX by asukaze ( http://www.asukaze.net/ ) */ /* A C-program for MT19937: Integer version (1999/10/28) */ /* genrand() generates one pseudorandom unsigned integer (32bit) */ /* which is uniformly distributed among 0 to 2^32-1 for each */ /* call. sgenrand(seed) sets initial values to the working area */ /* of 624 words. Before genrand(), sgenrand(seed) must be */ /* called once. (seed is any 32-bit integer.) */ /* Coded by Takuji Nishimura, considering the suggestions by */ /* Topher Cooper and Marc Rieffel in July-Aug. 1997. */ /* This library is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU Library General Public */ /* License as published by the Free Software Foundation; either */ /* version 2 of the License, or (at your option) any later */ /* version. */ /* This library is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* See the GNU Library General Public License for more details. */ /* You should have received a copy of the GNU Library General */ /* Public License along with this library; if not, write to the */ /* Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA */ /* 02111-1307 USA */ /* Copyright (C) 1997, 1999 Makoto Matsumoto and Takuji Nishimura. */ /* Any feedback is very welcome. For any question, comments, */ /* see http://www.math.keio.ac.jp/matumoto/emt.html or email */ /* matumoto@math.keio.ac.jp */ /* REFERENCE */ /* M. Matsumoto and T. Nishimura, */ /* "Mersenne Twister: A 623-Dimensionally Equidistributed Uniform */ /* Pseudo-Random Number Generator", */ /* ACM Transactions on Modeling and Computer Simulation, */ /* Vol. 8, No. 1, January 1998, pp 3--30. */ function bits(x){ str = ""; for(i=0; i<32; i++){ if((x % 2) == 1){ str = "1" + str; x = x - 1; }else{ str = "0" + str; } x = x / 2; } return str; } function bitxor(x,y){ str = ""; for(i=1; i<=32; i++){ if(mid(x,i,1) == mid(y,i,1)){ str = str + "0"; }else{ str = str + "1"; } } return str; } function bits2int(x){ val = 0; for(i=2; i<=32; i++){ if(mid(x,i,1) == "1"){ val = val * 2 + 1; }else{ val = val * 2; } } return val; } function mod65536(x){ INT_MAX = 2147483647; while(x > INT_MAX){ x = x - INT_MAX - 1; } return (x % 65536); } function begin() { X = Right-0 + 2; N = 624; INT_OVER = (65536*65536); seed = (3600 * GetHours()) + (60 * GetMinutes()) + GetSeconds(); for(i=2; i= INT_OVER){ seed2 = seed2 - INT_OVER; } seed2L = mod65536(seed2); seed = seed2L * 65536 + (3533 * seedL) + 1; L = left(bits(seed),16); [X,i] = U + L; seedL = mod65536(seed); seedU = (seed - seedL) / 65536; seed2 = (3533 * seedU + seedL); while(seed2 >= INT_OVER){ seed2 = seed2 - INT_OVER; } seed2L = mod65536(seed2); seed = seed2L * 65536 + (3533 * seedL) + 1; } [X,1] = 624; } function end() { DeleteCol(Right); } function next() { X = Right; mag01_0 = 0; mag01_1 = MATRIX_A; if([X,1] >= 624){ for (kk=0; kk<227; kk++) { y = "0" + left([X,kk+2], 1) + mid([X, kk+3], 2, 30); z = bitxor([X,kk+399], y); if(right([X, kk+3], 1) == "1"){ z = bitxor(z, "10011001000010001011000011011111"); } [X,kk+2] = z; } for(kk=kk; kk<623; kk++) { y = "0" + left([X,kk+2], 1) + mid([X, kk+3], 2, 30); z = bitxor([X,kk-225], y); if(right([X, kk+3], 1) == "1"){ z = bitxor(z, "10011001000010001011000011011111"); } [X,kk+2] = z; } y = "0" + left([X,625], 1) + mid([X, 2], 2, 30); z = bitxor([X,398], y); if(right([X, 2], 1) == "1"){ z = bitxor(z, "10011001000010001011000011011111"); } [X,625] = z; [X,1] = 0; } mti = ([X,1]-0); [X,1] = mti + 1; y = [X,mti+2]; y = bitxor(y, "00000000000" + left(y,21)); y = bitxor(y, bitxor(mid(y,8) + "0000000", "10011101001011000101011010000000")); y = bitxor(y, bitxor(mid(y,16) + "000000000000000", "11101111110001100000000000000000")); y = bitxor(y, "000000000000000000" + left(y,18)); return bits2int(y); } begin(); for(i=1; i<=100; i++){ [1,i] = (next() % 1000); } end();