fork download
  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. void init_by_array(unsigned long init_key[], int key_length);
  5. unsigned long genrand_int32(void);
  6.  
  7. constexpr int N = (1024 * 1024 * 128);
  8. constexpr int N2 = N / sizeof(int);
  9. static_assert(N % sizeof(int) == 0);
  10. static_assert(sizeof(int) == sizeof(LONG));
  11.  
  12. static int buff[N2];
  13. int main(int argc, char **argv) {
  14. HANDLE h;
  15. long unsigned int actualWrite;
  16. volatile LONG dmy;
  17.  
  18. if (argc != 2) {
  19. fprintf(stderr, "usage: %s <file>\n", argv[0]);
  20. exit(-1);
  21. }
  22.  
  23. /* srand() */
  24. unsigned long init[4]={0x314, 0x159, 0x265, 0x358}, length=4;
  25. init_by_array(init, length);
  26.  
  27. int n = 0;
  28. h = CreateFile(argv[1], GENERIC_WRITE, 0, 0, OPEN_ALWAYS, 0, 0);
  29. if (h != INVALID_HANDLE_VALUE) {
  30. for (;;) {
  31. dmy = 0;
  32. SetFilePointer(h, 0, (LONG * volatile)&dmy, FILE_END);
  33.  
  34. for (int i = 0; i < N2; i++) {
  35. buff[i] = genrand_int32();
  36. }
  37.  
  38. WriteFile(h, buff, N, &actualWrite, 0);
  39. if (actualWrite != N) {
  40. printf("actual write bytes: %d, exit.\n", actualWrite);
  41. break;
  42. }
  43. FlushFileBuffers(h);
  44. printf("<%d>\n", n++);
  45. }
  46. CloseHandle(h);
  47. } else {
  48. printf("cannot open the file %s\n", argv[1]);
  49. exit(1);
  50. }
  51. printf("stoped.\n");
  52. return 0;
  53. }
  54.  
  55. /*
  56.   A C-program for MT19937, with initialization improved 2002/1/26.
  57.   Coded by Takuji Nishimura and Makoto Matsumoto.
  58. */
  59.  
  60. #include <stdio.h>
  61.  
  62. /* Period parameters */
  63. #define N 624
  64. #define M 397
  65. #define MATRIX_A 0x9908b0dfUL /* constant vector a */
  66. #define UPPER_MASK 0x80000000UL /* most significant w-r bits */
  67. #define LOWER_MASK 0x7fffffffUL /* least significant r bits */
  68.  
  69. static unsigned long mt[N]; /* the array for the state vector */
  70. static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
  71.  
  72. void init_genrand(unsigned long s)
  73. {
  74. mt[0]= s & 0xffffffffUL;
  75. for (mti=1; mti<N; mti++) {
  76. mt[mti] =
  77. (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
  78. /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
  79. /* In the previous versions, MSBs of the seed affect */
  80. /* only MSBs of the array mt[]. */
  81. /* 2002/01/09 modified by Makoto Matsumoto */
  82. mt[mti] &= 0xffffffffUL;
  83. /* for >32 bit machines */
  84. }
  85. }
  86.  
  87. void init_by_array(unsigned long init_key[], int key_length)
  88. {
  89. int i, j, k;
  90. init_genrand(19650218UL);
  91. i=1; j=0;
  92. k = (N>key_length ? N : key_length);
  93. for (; k; k--) {
  94. mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
  95. + init_key[j] + j;
  96. mt[i] &= 0xffffffffUL;
  97. i++; j++;
  98. if (i>=N) { mt[0] = mt[N-1]; i=1; }
  99. if (j>=key_length) j=0;
  100. }
  101. for (k=N-1; k; k--) {
  102. mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
  103. - i;
  104. mt[i] &= 0xffffffffUL;
  105. i++;
  106. if (i>=N) { mt[0] = mt[N-1]; i=1; }
  107. }
  108.  
  109. mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
  110. }
  111.  
  112. /* generates a random number on [0,0xffffffff]-interval */
  113. unsigned long genrand_int32(void)
  114. {
  115. unsigned long y;
  116. static unsigned long mag01[2]={0x0UL, MATRIX_A};
  117. /* mag01[x] = x * MATRIX_A for x=0,1 */
  118.  
  119. if (mti >= N) { /* generate N words at one time */
  120. int kk;
  121.  
  122. if (mti == N+1) /* if init_genrand() has not been called, */
  123. init_genrand(5489UL); /* a default initial seed is used */
  124.  
  125. for (kk=0;kk<N-M;kk++) {
  126. y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
  127. mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
  128. }
  129. for (;kk<N-1;kk++) {
  130. y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
  131. mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
  132. }
  133. y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
  134. mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
  135.  
  136. mti = 0;
  137. }
  138.  
  139. y = mt[mti++];
  140.  
  141. /* Tempering */
  142. y ^= (y >> 11);
  143. y ^= (y << 7) & 0x9d2c5680UL;
  144. y ^= (y << 15) & 0xefc60000UL;
  145. y ^= (y >> 18);
  146.  
  147. return y;
  148. }
  149.  
  150. /* end */
  151.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:10: fatal error: windows.h: No such file or directory
 #include <windows.h>
          ^~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty