fork download
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdint.h>
  4.  
  5. void init_by_array(unsigned long init_key[], int key_length);
  6. unsigned long genrand_int32(void);
  7.  
  8. typedef uint32_t Fnv32_t;
  9. Fnv32_t fnv_32a_str(char *str, Fnv32_t hval);
  10.  
  11. constexpr int N_MEGA = (1024 * 1024);
  12. static_assert(N_MEGA % sizeof(int) == 0);
  13. static_assert(sizeof(int) == sizeof(LONG));
  14.  
  15. mySrand(unsigned long init[]) {
  16. char buff[256] = {0x00,};
  17. Fnv32_t hval = 0;
  18. SYSTEMTIME systime;
  19. ::GetLocalTime(&systime);
  20. sprintf(buff, "%d%d%d%d%d%d%d%d",
  21. systime.wYear
  22. ,systime.wMonth
  23. ,systime.wDay
  24. ,systime.wDayOfWeek
  25. ,systime.wHour
  26. ,systime.wMinute
  27. ,systime.wSecond
  28. ,systime.wMilliseconds);
  29. hval = init[0] = fnv_32a_str(buff, hval);
  30. hval = init[1] = fnv_32a_str(buff, hval);
  31. hval = init[2] = fnv_32a_str(buff, hval);
  32. init[3] = fnv_32a_str(buff, hval);
  33. }
  34.  
  35.  
  36. MyWriteFile(HANDLE h, int *buff, int nbyte) {
  37. unsigned long int actualWrite;
  38. int c = 0;
  39. for (;;) {
  40. ::WriteFile(h, buff, nbyte, &actualWrite, 0);
  41. if (actualWrite == nbyte)
  42. break;
  43. printf("[%d] actualWrite = %d\n", c++, actualWrite);
  44. }
  45. }
  46.  
  47. int main(int argc, char **argv) {
  48. HANDLE h;
  49. volatile LONG dmy;
  50.  
  51. if (argc != 3) {
  52. fprintf(stderr, "usage: %s <size> <file>\n", argv[0]);
  53. exit(-1);
  54. }
  55.  
  56. int psize = atoi(argv[1]);
  57. if (psize == 0) {
  58. fprintf(stderr, "%s: not available size = %d\n", argv[0], argv[1]);
  59. exit(1);
  60. }
  61.  
  62. int *buff = (int *)malloc(N_MEGA * psize);
  63. if (buff == 0) {
  64. fprintf(stderr, "%s: cannot allocate needed memory : %d MiByte.\n", argv[0], psize);
  65. exit(1);
  66. }
  67.  
  68. /* srand() */
  69. unsigned long init[4], length=4;
  70. mySrand(init);
  71. init_by_array(init, length);
  72.  
  73. int n = 0;
  74. h = ::CreateFile(argv[2], GENERIC_WRITE, 0, 0, OPEN_ALWAYS, 0, 0);
  75. if (h != INVALID_HANDLE_VALUE) {
  76. for (;;) {
  77. dmy = 0;
  78. ::SetFilePointer(h, 0, (LONG * volatile)&dmy, FILE_END);
  79. for (int i = 0; i < psize * N_MEGA / sizeof(int); i++) {
  80. buff[i] = genrand_int32();
  81. }
  82. MyWriteFile(h, buff, psize * N_MEGA);
  83. ::FlushFileBuffers(h);
  84. printf("<%d>\n", n++);
  85. }
  86. ::CloseHandle(h);
  87. } else {
  88. printf("cannot open the file %s\n", argv[2]);
  89. exit(1);
  90. }
  91. free(buff);
  92. printf("stoped.\n");
  93. return 0;
  94. }
  95.  
  96. /*
  97.   A C-program for MT19937, with initialization improved 2002/1/26.
  98.   Coded by Takuji Nishimura and Makoto Matsumoto.
  99. */
  100.  
  101. #include <stdio.h>
  102.  
  103. /* Period parameters */
  104. #define N 624
  105. #define M 397
  106. #define MATRIX_A 0x9908b0dfUL /* constant vector a */
  107. #define UPPER_MASK 0x80000000UL /* most significant w-r bits */
  108. #define LOWER_MASK 0x7fffffffUL /* least significant r bits */
  109.  
  110. static unsigned long mt[N]; /* the array for the state vector */
  111. static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
  112.  
  113. void init_genrand(unsigned long s)
  114. {
  115. mt[0]= s & 0xffffffffUL;
  116. for (mti=1; mti<N; mti++) {
  117. mt[mti] =
  118. (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
  119. /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
  120. /* In the previous versions, MSBs of the seed affect */
  121. /* only MSBs of the array mt[]. */
  122. /* 2002/01/09 modified by Makoto Matsumoto */
  123. mt[mti] &= 0xffffffffUL;
  124. /* for >32 bit machines */
  125. }
  126. }
  127.  
  128. void init_by_array(unsigned long init_key[], int key_length)
  129. {
  130. int i, j, k;
  131. init_genrand(19650218UL);
  132. i=1; j=0;
  133. k = (N>key_length ? N : key_length);
  134. for (; k; k--) {
  135. mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
  136. + init_key[j] + j;
  137. mt[i] &= 0xffffffffUL;
  138. i++; j++;
  139. if (i>=N) { mt[0] = mt[N-1]; i=1; }
  140. if (j>=key_length) j=0;
  141. }
  142. for (k=N-1; k; k--) {
  143. mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
  144. - i;
  145. mt[i] &= 0xffffffffUL;
  146. i++;
  147. if (i>=N) { mt[0] = mt[N-1]; i=1; }
  148. }
  149.  
  150. mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
  151. }
  152.  
  153. /* generates a random number on [0,0xffffffff]-interval */
  154. unsigned long genrand_int32(void)
  155. {
  156. unsigned long y;
  157. static unsigned long mag01[2]={0x0UL, MATRIX_A};
  158. /* mag01[x] = x * MATRIX_A for x=0,1 */
  159.  
  160. if (mti >= N) { /* generate N words at one time */
  161. int kk;
  162.  
  163. if (mti == N+1) /* if init_genrand() has not been called, */
  164. init_genrand(5489UL); /* a default initial seed is used */
  165.  
  166. for (kk=0;kk<N-M;kk++) {
  167. y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
  168. mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
  169. }
  170. for (;kk<N-1;kk++) {
  171. y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
  172. mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
  173. }
  174. y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
  175. mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
  176.  
  177. mti = 0;
  178. }
  179.  
  180. y = mt[mti++];
  181.  
  182. /* Tempering */
  183. y ^= (y >> 11);
  184. y ^= (y << 7) & 0x9d2c5680UL;
  185. y ^= (y << 15) & 0xefc60000UL;
  186. y ^= (y >> 18);
  187.  
  188. return y;
  189. }
  190.  
  191. /*--------------------*\
  192.   /*
  193.  * hash_32 - 32 bit Fowler/Noll/Vo FNV-1a hash code
  194.  *
  195. */
  196.  
  197. #include <stdlib.h>
  198. /*#include "fnv.h"*/
  199.  
  200. #define FNV1_32_INIT ((Fnv32_t)0x811c9dc5)
  201. #define FNV1_32A_INIT FNV1_32_INIT
  202. #define FNV_32_PRIME ((Fnv32_t)0x01000193)
  203.  
  204. /*
  205.  * fnv_32a_str - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a string
  206.  *
  207.  * input:
  208.  * str - string to hash
  209.  * hval - previous hash value or 0 if first call
  210.  *
  211.  * returns:
  212.  * 32 bit hash as a static hash type
  213.  *
  214.  * NOTE: To use the recommended 32 bit FNV-1a hash, use FNV1_32A_INIT as the
  215.  * hval arg on the first call to either fnv_32a_buf() or fnv_32a_str().
  216.  */
  217. Fnv32_t fnv_32a_str(char *str, Fnv32_t hval)
  218. {
  219. unsigned char *s = (unsigned char *)str; /* unsigned string */
  220.  
  221. while (*s) {
  222. hval ^= (Fnv32_t)*s++;
  223. hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
  224. }
  225.  
  226. return hval;
  227. }
  228.  
  229. /* end */
  230.  
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