initByArray method

void initByArray(
  1. dynamic initKey,
  2. dynamic keyLength
)

Implementation

void initByArray(var initKey, var keyLength) {
  //c//int i, j, k;
  late int i;
  late int j;
  late dynamic k;
  //c//init_genrand(19650218);
  initGenrand(19650218);
  i = 1;
  j = 0;
  k = (N > keyLength ? N : keyLength);
  for (; k; k--) {
    //c//mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525))
    //c// + init_key[j] + j; /* non linear */
    mt[i] = addition32(
        addition32(
            unsigned32(mt[i] ^
                multiplication32(
                    unsigned32(mt[i - 1] ^ (mt[i - 1] >> 30)), 1664525)),
            initKey[j]),
        j);
    mt[i] =
        //c//mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
        unsigned32(mt[i] & 0xffffffff);
    i++;
    j++;
    if (i >= N) {
      mt[0] = mt[N - 1];
      i = 1;
    }
    if (j >= keyLength) j = 0;
  }
  for (k = N - 1; k; k--) {
    //c//mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941))
    //c//- i; /* non linear */
    mt[i] = subtraction32(
        unsigned32(mt[i] ^
            multiplication32(
                unsigned32(mt[i - 1] ^ (mt[i - 1] >> 30)), 1566083941)),
        i);
    //c//mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
    mt[i] = unsigned32(mt[i] & 0xffffffff);
    i++;
    if (i >= N) {
      mt[0] = mt[N - 1];
      i = 1;
    }
  }
  mt[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */
}