Created
June 1, 2016 20:56
-
-
Save Quintus/2a0ec1eb67055ddd37f915e43eb83e7a to your computer and use it in GitHub Desktop.
PRNG demo for @sauer2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* PRNG demonstration program. | |
* Compile with: | |
* $ gcc -Wall rand.c -o rand | |
* Run as: | |
* ./rand | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char* argv[]) | |
{ | |
unsigned int seed = 0; | |
int i = 0; | |
if (argc > 1) { | |
printf("Initialise the random number generator with the given seed\n"); | |
printf("and print a sequence of five random numbers.\n"); | |
return 0; | |
} | |
printf("Enter a seed of your choice: "); | |
scanf("%u", &seed); | |
printf("Seeding PRNG with %u\n", seed); | |
srand(seed); | |
printf("Here are five random numbers between 0 and 100:\n"); | |
for(i=0; i < 5; i++) | |
printf("%d\n", rand() % 100); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment