#include #include /* has rand(), srand(), RAND_MAX */ int main(void) { int seed; printf("seed?\n"); if (scanf("%d", &seed) != 1) { printf("invalid input\n"); return 1; } if (seed <= 0) { printf("invalid input\n"); return 1; } srand(seed); /* FIXME: * replace the rest of this code with your code (but okay to keep * anything you think will help). */ printf("%d\n", rand()); printf("%d\n", rand()); printf("%d\n", rand()); printf("%d\n", rand()); puts(""); /* prints a newline */ int n = rand(); int num_bins = 6; printf("next element %d\n", n); printf("one way to map to [0..5] %d: %d\n", n, n % num_bins); printf("another way map to [0..5] %d: %d\n", n, (int) ((((double) num_bins) * n)/(RAND_MAX+1.0))); return 0; }