Share this page

# Example: srand

The following example generates 2 random numbers, each kept within a specific range using the mod (%) operator.

     // Srand is called before rand

        srand(time(NULL));

    // Generate some random numbers

        lr_output_message ("A number between 0 and 100: %d\n", rand() % 100);
        lr_output_message ("A number between 20 and 30: %d\n", rand() % 10+20);

    Example: Output:
    Action.c(7): A number between 0 and 100: 72
    Action.c(8): A number between 20 and 30: 28

Tips to improve your search results... VuGen Function Reference Version 25.1-25.3 Function Reference 25.1-25.3 All View Local Help Center View Online Help Center Version: