Random number generator (device): Difference between revisions

Content deleted Content added
→‎{{header|C}}: Add alternate solutions using BSD arc4random() and using OpenSSL RAND_bytes().
→‎{{header|C}}: Add alternate solution for Windows using CryptGenRandom.
Line 80:
}
printf("%" PRIu32 "\n", v);
return 0;
}</lang>
 
=== Windows ===
{{works with|MinGW}}
 
<lang c>#include <stdio.h> /* printf */
#include <windows.h>
#include <wincrypt.h> /* CryptAcquireContext, CryptGenRandom */
 
int
main()
{
HCRYPTPROV p;
ULONG i;
 
if (CryptAcquireContext(&p, NULL, NULL,
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) == FALSE) {
fputs("CryptAcquireContext failed.\n", stderr);
return 1;
}
if (CryptGenRandom(p, sizeof i, (BYTE *)&i) == FALSE) {
fputs("CryptGenRandom failed.\n", stderr);
return 1;
}
printf("%lu\n", i);
CryptReleaseContext(p, 0);
return 0;
}</lang>