title: C - how to read data from /dev/urandom into a uint64_t variable?
body: <p>As will probably be painfully obvious, I do not normally program in C.  However, after a lot of searching it seems to be the most efficient language to implement what I want to do, namely generate a large number (10 million) of random integers quickly (using an Xorshift* algorithm). The intention is to seed it with /dev/urandom.</p>
  
  <p>I have cobbled together the code below from a variety of sources.  It now compiles without warning or error with gcc 5.4.  </p>
  
  <p>However, when run, the program is not pulling a random seed from /dev/urandom (or at least it's not populating the value of "seed" correctly). In fact, the value of "seed" seems to always end up the same on my system - 4195584.</p>
  
  <p>In summary, the variation of Xorshift* I cribbed from <a href="https://en.wikipedia.org/wiki/Xorshift#Variations" rel="nofollow">here</a> requires a uint64_t seed, which I want to pull from /dev/urandom, which is not working currently in my program as it stands.</p>
  
  <p>Environment is Linux (Ubuntu 16.04).</p>
  
  <p>Assistance appreciated.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdint.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;inttypes.h&gt;
  
  
  
  int main (void) {
  
  uint64_t seed;
  uint64_t newval;
  long int a;
  
  int fd = open("/dev/urandom", O_RDONLY);
  read(fd,(uint64_t*)seed,sizeof(seed));
  close(fd);
  
  printf("Seed:");
  printf("%" PRIu64 "\n",seed);
  
  
  for ( a = 1; a &lt;= 10000000; a = a + 1 ) {
    seed ^= seed &lt;&lt; 12;
    seed ^= seed &gt;&gt; 25;
    seed ^= seed &lt;&lt; 27;
    seed = seed * UINT64_C(2685821657736338717);
    newval = abs(seed);
    printf("%" PRIu64 "\n",newval);
  }
  
  }
  </code></pre>