Advertisement
NickG

Untitled

Sep 15th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. char* genset(int num, int max, int mod) {
  7.     char *temp;
  8.     do {
  9.         temp = (char *)calloc(num+1, sizeof(char));
  10.         for(int i=0; i<num; i++)
  11.             sprintf(temp, "%s%d", temp, (rand()%mod));
  12.     } while(atoi(temp)>max);
  13.     return temp;
  14. }
  15.  
  16. int main(int argc, char **argv) {
  17.     srand(time(NULL));
  18.     printf("%s-%s-%s\n", genset(3, 999, 8), genset(3, 742, 10), genset(4, 9999, 10));
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement