C语言中生成指定范围内的随机数

1664阅读 0评论2012-03-22 LoveJJ_2011
分类:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/time.h>
  5. int main()
  6. {
  7.     struct timeval st;
  8.     gettimeofday( &st, NULL );
  9.     srand(st.tv_usec);
  10.     printf( "%d -> %d\n", st.tv_usec, 1 + rand() % 9 );
  11.     return 0;
  12. }

  13. /*打印结果*/

  14. /*
  15. $ ./a.out
  16. 9
  17. $ ./a.out
  18. 6
  19. $ ./a.out
  20. 3
  21. $ ./a.out
上一篇:一些经典排序算法的实现(C++实现)
下一篇:Linux网络编程之广播