当前位置:首页 > 数据库 > 正文

linux rand application

2020-02-12 数据库

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 }

 

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/SQL/14474.html