linux rand application

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("%d\t", arr[i]);
 18     }
 19 
 20 
 21     return 0;
 22 }

https://www.cnblogs.com/tonyc/p/7732119.html 

posted @ 2019-11-19 15:22  叕叒双又  阅读(206)  评论(0编辑  收藏  举报