(Unicode C) Generating Random Integer in Range
Demonstrates how to generate random integers in a specified range.
#include <C_CkGlobalW.h>
#include <C_CkPrngW.h>
void ChilkatSample(void)
{
HCkGlobalW chilkatGlob;
BOOL success;
HCkPrngW fortuna;
int i;
// All Chilkat classes can be unlocked at once at the beginning of a program
// by calling UnlockBundle. It requires a Bundle unlock code.
chilkatGlob = CkGlobalW_Create();
success = CkGlobalW_UnlockBundle(chilkatGlob,L"Anything for 30-day trial.");
if (success != TRUE) {
wprintf(L"%s\n",CkGlobalW_lastErrorText(chilkatGlob));
CkGlobalW_Dispose(chilkatGlob);
return;
}
fortuna = CkPrngW_Create();
// Generate random integers between 12 and 24 inclusive
for (i = 0; i <= 100; i++) {
wprintf(L"%d\n",CkPrngW_RandomInt(fortuna,12,24));
}
CkGlobalW_Dispose(chilkatGlob);
CkPrngW_Dispose(fortuna);
}
|