#include #include #include #include // Written by Chris.McDonald@uwa.edu.au // RETURNS A PROBABILITY IN THE RANGE [0.0 .. 1.0] double PROB(void) { return ((double)rand()/(double)RAND_MAX); } // SIMULATE SLOTTED-ALOHA COMMUNICATION, RETURN UTILISATION OF THE MEDIUM double SlottedAloha(int nslots, int nnodes, double ProbNew, double ProbRetry) { #define FOREACH_TIME_SLOT for(int s=0 ; s1.0 || ProbRetry<0.0 || ProbRetry>1.0) { fprintf(stderr, "Usage: %s nslots nnodes prob-new prob-Tx\n", argv[0]); exit(EXIT_FAILURE); } // SEED RANDOM NUMBER SEQUENCE srand((long)time(NULL)); // SIMULATE THE COMMUNICATION, PRINT ITS UTILISATION printf("%.2f\n", 100.0 * SlottedAloha(nslots, nnodes, ProbNew, ProbRetry)); exit(EXIT_SUCCESS); } // vim: ts=8 sw=4