// A quick demo of random numbers

// Marc Chee (marc.chee@unsw.edu.au)

#include <stdio.h>
#include <stdlib.h>

#define MAX_NUMS 10

int main(int argc, char *argv[]) {
    if (argc > 1) {
        // if we received a command line argument, 
        // use that as our random seed
        srand(strtol(argv[1], NULL, 10));
    }

    int i = 0;
    while (i < MAX_NUMS) {
        printf("%d\n", rand());
        i++;
    }
}

Resource created Friday 13 September 2019, 02:04:32 PM.

file: randDemo.c


Back to top

COMP1511 19T3 (Programming Fundamentals) is powered by WebCMS3
CRICOS Provider No. 00098G