title: Alternative to rand() or random() in C++
body: <p>I want to replace <a href="https://www.cplusplus.com/reference/cstdlib/rand/" rel="nofollow noreferrer">rand()</a> (or random()) with a (cryptographically) <strong>secure</strong> random number generator. It should also be <strong>portable</strong>.</p>
  <p>I have already found two alternatives:</p>
  <ol>
  <li><a href="https://www.openssl.org/docs/man1.1.1/man3/RAND_bytes.html" rel="nofollow noreferrer">RAND_bytes()</a></li>
  <li><a href="https://man7.org/linux/man-pages/man2/getrandom.2.html" rel="nofollow noreferrer">getrandom()</a></li>
  </ol>
  <p>However, I don't know how to convert the following simple code into these alternatives:</p>
  <pre><code>rand() % X     // X is an integer
  </code></pre>
  <p>Or do you know better generators?</p>