听AC大神说随机大数不能用两个随机数乘,所以就用每一位来rand
 
 1 #include <stdlib.h>
 2 #include <stdio.h>
 3 #include <time.h>
 4 #define MAX 10000000
 5 int Rand(int k,int max)
 6 {
 7    int     a = 0;
 8     for(int i =1;i <= k;i ++)
 9     {
10        a *= 10;
11        a += rand()%10;
12     }
13     if(a <= max)
14      return a;
15     else return Rand(k,max);
16 
17 }
18 
19 int main(){
20     freopen("input.txt","w",stdout);
21     srand( (int)time( NULL ));
22     printf("%d\n",MAX);
23     for(int i =1 ;i<= MAX;i ++)
24      {
25        printf("%d\n",Rand(4,9999));
26      }
27      //printf("%d\n",Rand(9));
28   return 0;
29 }
View Code

 

posted on 2013-11-15 14:47  dark_dream  阅读(259)  评论(0编辑  收藏  举报