title: How can I use Linux getrandom system call to generate a random number within a range?
body: <p>I have the following piece of code</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;sys/syscall.h&gt;
  #include &lt;linux/random.h&gt;
  
  unsigned long int s;
  syscall(SYS_getrandom, &amp;s, sizeof(unsigned long int), 1);
  std::cout &lt;&lt; s &lt;&lt; std::endl;
  </code></pre>
  
  <p>According to <a href="http://man7.org/linux/man-pages/man2/getrandom.2.html" rel="nofollow noreferrer">GETRANDOM(2)</a> it returns random numbers from /dev/random or /dev/urandom with high entropy.</p>
  
  <p>How can I use it to return numbers within a range? The range I'm using is <s>[0 - 2^125]</s> [0 - 125^2]</p>