Sample code for 30+ languages & platforms
Unicode C

Generating Random Integer in Range

See more PRNG Examples

Demonstrates how to generate random integers in a specified range.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkPrngW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkPrngW fortuna;
    int i;

    success = FALSE;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    success = FALSE;

    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));
    }



    CkPrngW_Dispose(fortuna);

    }