zoukankan      html  css  js  c++  java
  • 快速生成10亿随机不重复数据代码(转)

    #include     <cstdlib>   
    #include     
    <iostream>  
    #include     
    <windows.h>   

    using   namespace   std;


    char   map2char[]={'1','2','3','4','5','6','7','8','b','c','d','e','f','g','h','i',
    'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y'}
    ;

    void    getbit( unsigned e, char *s, int offset ){
        
    int i=17;
        
    while( i>=0 ){
            s[
    18*offset+i]=((e>>i)&1);
            
    --i;
        }
       
    }


    int   main(int   argc,   char   *argv[])   
    {      
        
        srand(GetTickCount());
        
    char bit[90], S[90];
        
    forint i=0; i<sizeof(bit); ++i ) bit[i]=0, S[i]=0;
        unsigned  x, T;
        
    forint k=0; k<5++k ){
            
    do
            x
    =rand();
            
    while( x==0 );
            getbit( x, S, k);
            getbit( x, bit, k );
        }

        unsigned head
    =89;
        unsigned  j
    =0, time=GetTickCount(), Max=1000000;
        
    do
            
    ++j;
            T
    =(bit[head]&1)^(bit[(head-83)%90]&1)^(bit[(head-84)%90]&1)^(bit[(head-86)%90]&1)^(bit[(head-89)%90]&1);
            bit[head]
    =T;
            head
    =(head+1)%90;
            
    forint index=0; index<18++index ){
                
    int num=0;
                
    forint j=0; j<5++j )
                    num
    +=(bit[(head+5*index+j)%90]==0)? 0 : (1<<j);            
                cout
    <<map2char[num];        
            }

            cout
    <<endl;        
        }
    while( j<Max );
        cout
    <<"time: "<<GetTickCount()-time<<" ms!\n";      
        
        system(
    "PAUSE");   
        
    return   EXIT_SUCCESS;   
    }
     
  • 相关阅读:
    Python shutil模块
    Flask 上传文件
    Flask DBUtils
    flash-session
    Flash 上下文管理
    python 栈
    python 偏函数
    threding.local
    next() 与 nextLine() 区别
    Thread.sleep(1000*3); // 休眠3秒
  • 原文地址:https://www.cnblogs.com/feng801/p/1452702.html
Copyright © 2011-2022 走看看