Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define N 7
- void print(char *rand, int n) {
- int i;
- printf("randoms: [");
- for (i = 0; i < n; i++) {
- printf("%d", rand[i]);
- if (i < n - 1) printf(", ");
- }
- printf("]\n");
- }
- int main(void) {
- char randoms[] = { 0, 0, 0, 0, 0, 0, 0 };
- int i, j, trial;
- srand((unsigned int) time(NULL));
- trial = rand() % 7 + 3;
- for (i = 0; i < trial; i++) {
- if (rand() % 2) {
- j = rand() % N;
- randoms[j] = 1;
- print(randoms, N);
- randoms[j] = 0;
- }
- else print(randoms, N);
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement