(C) Generating Random Integer in Range
Demonstrates how to generate random integers in a specified range.
#include <C_CkGlobal.h>
#include <C_CkPrng.h>
void ChilkatSample(void)
{
HCkGlobal chilkatGlob;
BOOL success;
HCkPrng 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 = CkGlobal_Create();
success = CkGlobal_UnlockBundle(chilkatGlob,"Anything for 30-day trial.");
if (success != TRUE) {
printf("%s\n",CkGlobal_lastErrorText(chilkatGlob));
CkGlobal_Dispose(chilkatGlob);
return;
}
fortuna = CkPrng_Create();
// Generate random integers between 12 and 24 inclusive
for (i = 0; i <= 100; i++) {
printf("%d\n",CkPrng_RandomInt(fortuna,12,24));
}
CkGlobal_Dispose(chilkatGlob);
CkPrng_Dispose(fortuna);
}
|