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;   
    }
     
  • 相关阅读:
    TCP/IP
    Socket通信
    Dubbo详解
    高并发详解
    P3-DataBase
    JAVA基础学习之路(十)this关键字
    [SHELL]输出目录下所有的可执行文件,批量创建用户
    JAVA基础学习之路(八)[1]String类的基本特点
    [MYSQL][2]索引
    [MYSQL][1]创建,修改,删除表
  • 原文地址:https://www.cnblogs.com/feng801/p/1452702.html
Copyright © 2011-2022 走看看