Skip to content

Instantly share code, notes, and snippets.

@folivetti
Created March 16, 2023 16:17
Show Gist options
  • Save folivetti/ee2e3acc6779ff331391e1d78f3fcd9f to your computer and use it in GitHub Desktop.
Save folivetti/ee2e3acc6779ff331391e1d78f3fcd9f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[]) {
int n, min, max, x, i;
time_t t;
srand((unsigned) time(&t));
if (argc < 3) {
printf("Uso: ./gerar n min max");
return -1;
}
n = atoi(argv[1]);
min = atoi(argv[2]);
max = atoi(argv[3]);
for (i=0; i<n; i++) {
x = min + (int)((double)rand() / ((double)RAND_MAX / (max - min + 1) + 1));
printf("%d", x);
if (i < n-1) printf(" ");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment