import strutils, sequtils, math, sets, times var start = cpuTime() const N: int = 624 M: int = 397 MATRIX_A: cuint = 0x9908b0df.cuint UPPER_MASK: cuint = 0x80000000.cuint LOWER_MASK: cuint = 0x7fffffff.cuint var mt = newSeq[cuint](0) mti: int = N + 1 proc init_genrand(s: cuint) = mt.add(s and 0xffffffff.cuint) for mti in 1.. key_length: N else: key_length while k > 0: mt[i] = (mt[i] xor ((mt[i-1] xor (mt[i-1] shr 30)) * 1664525.cuint)) + init_key[j].cuint + j.cuint mt[i] = mt[i] and 0xffffffff.cuint i += 1 j += 1 if i >= N: mt[0] = mt[N-1] i = 1 if j >= key_length: j = 0 k -= 1 for k in countdown(N-1, 1): mt[i] = (mt[i] xor ((mt[i-1] xor (mt[i-1] shr 30)) * 1566083941.cuint)) - i.cuint mt[i] = mt[i] and 0xffffffff.cuint i += 1 if i >= N: mt[0] = mt[N-1] i = 1 mt[0] = 0x80000000.cuint proc genrand_int32():cuint = var y: cuint var mag01 = newSeq[cuint](2) mag01[0] = 0x0 mag01[1] = MATRIX_A if mti.int >= N: if mti == N+1: init_genrand(5489) for kk in 0.. N-M-1: y = (mt[kk] and UPPER_MASK) or (mt[kk+1] and LOWER_MASK) mt[kk] = mt[kk+M] xor (y shr 1) xor mag01[(y and 0x1).int] for kk in N-M.. N-2: y = (mt[kk] and UPPER_MASK) or (mt[kk+1] and LOWER_MASK) mt[kk] = mt[kk+(M-N)] xor (y shr 1) xor mag01[(y and 0x1).int] y = (mt[N-1] and UPPER_MASK) or (mt[0] and LOWER_MASK) mt[N-1] = mt[M-1] xor (y shr 1) xor mag01[(y and 0x1).int] mti = 0 y = mt[mti.int] mti += 1 y = y xor (y shr 11) y = y xor (y shl 7) and 0x9d2c5680.cuint y = y xor (y shl 15) and 0xefc60000.cuint y = y xor (y shr 18) return y proc genrand_int31():int = return (genrand_int32() shr 1).int proc myrand:int = return genrand_int31() proc shuffle*(arr: var seq) = var koko: int = arr.len for i in 0.. ele.b: win += 1 elif ele.a < ele.b: lose += 1 if win > lose: check += 1 echo check / all