title: CryptGenRandom output not getting same as rand() call
body: <p>I tried to create random number using CryptGenRandom() call for avoiding cryptographic attack.
  I tried to run follwing code which prints both rand call and CryptGenRandom() call.</p>
  
  <pre><code>    HCRYPTPROV hProvider = 0;
  
      const DWORD dwLength = 5;
  
      BYTE pbBuffer[dwLength] = {};
  
      if (!::CryptAcquireContext(&amp;hProvider, 0, 0, PROV_RSA_FULL,  CRYPT_VERIFYCONTEXT|CRYPT_SILENT))
  
      return 1;
  
      srand((unsigned)time (0));
      for(int i=0; i&lt;10; ++i)
          cout&lt;&lt;"rand()::"&lt;&lt;i&lt;&lt;":"&lt;&lt;rand()&lt;&lt;endl;
  
      for (DWORD i = 0; i &lt; dwLength; ++i)
      {
          if (!::CryptGenRandom(hProvider, dwLength, pbBuffer))
          {
              ::CryptReleaseContext(hProvider, 0);
              return 1;
          }
       std::cout &lt;&lt; "windows::"&lt;&lt;i&lt;&lt;"::"&lt;&lt;static_cast&lt;unsigned int&gt;(pbBuffer[0])&lt;&lt; std::endl;
      }
  
      if (!::CryptReleaseContext(hProvider, 0))
      return 1;
  </code></pre>
  
  <p>but output of this getting for <code>rand()</code> call is</p>
  
  <pre><code>rand()::0:9754
  rand()::1:526
  rand()::2:29162
  rand()::3:10461
  rand()::4:31585
  rand()::5:15594
  rand()::6:12157
  rand()::7:19178
  rand()::8:5413
  rand()::9:16157
  </code></pre>
  
  <p>and <code>CryptGenRandom()</code> call is giving</p>
  
  <pre><code>windows::0::167
  windows::1::138
  windows::2::197
  windows::3::101
  windows::4::44
  </code></pre>
  
  <p>Can anyone help me to get same output which is giving rand() call using CryptGenRandom?
  CryptGenRandom() is giving only 3 digit random numbers which not sufficient for setting values for sleep calls which I am using in my code.    </p>