linux rand application

时间:2022-02-15 05:12:19

code:

  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <time.h>
  4 
  5 #define random_1(a, b) ((rand()%(b - a))   a)
  6 #define random_2(a, b) ((rand()%(b - a   1))   a)
  7 
  8 int main(int argc, char **argv)
  9 {
 10     srand((int)time(NULL));                                               
 11     int arr[10];
 12     for(int i = 0; i < 10; i  ){
 13         arr[i] = random_1(1, 20);
 14     }
 15 
 16     for(int i = 0; i < 10; i  ){
 17         printf("%dt", arr[i]);
 18     }
 19 
 20 
 21     return 0;
 22 }