zoukankan      html  css  js  c++  java
  • C++

    #include <iostream>
    #include <string>
    #include <ctime>
    #include <Windows.h>
    
    using namespace std;
    
    //////////////////////////////////////////////////////////
    // 全局静态随机数种子
    static int g_nSeed = time(NULL);
    
    //
    // 函数                --            int GetRandNum(int , int)
    //
    // 功能                --            获取随机数
    //
    // @param1         --            随机范围 : 起始
    // @param2         --            随机范围 : 终止
    //
    // 返回值             --            随机数
    //
    int GetRandNum(int nMin, int nMax)
    {
        srand(g_nSeed);
        g_nSeed = rand();
        return (nMin + (rand()) % (nMax - nMin));
    }
    
    //
    //    函数                --            char GetChar(BOOL)
    //
    //   功能                --            获取字符
    //
    //    @param           --            默认为:TRUE;        TRUE:账号字符;   FALSE:密码字符;
    //
    //    返回值             --            1.@param == TRUE,    返回账号字符
    //                                     2.@param == FALSE,    返回密码字符
    //
    char GetChar(BOOL bIsAccount = TRUE)
    {
        string strLib("");
        if ( bIsAccount )
        {
            strLib.append(
                "abcdefghijklmnopqrstuvwxyz"
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                "123456789");
        }
        else
        {
            strLib.append(
                "abcdefghijklmnopqrstuvwxyz"
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                "123456789"
                "!@#$%^&*()"
                "`~-=+[]{}\|;:'",<.>/?");
        }
    
        char chRet = strLib[GetRandNum(0, strLib.size())];
        return chRet;
    }
    
    //
    //    函数                --            string GetAccountNumOrPassWord(BOOL)
    //
    //    功能                --            获取字符
    //
    //    @param           --            默认为:TRUE;        TRUE:生成账号字符串;   FALSE:生成密码字符串;
    //
    //    返回值              --            1.@param == TRUE,    返回账号字符串;
    //                                     2.@param == FALSE,    返回密码字符串;
    //
    string GetAccountNumOrPassWord(int nMIn, int nMax, BOOL bIsAccount = TRUE)
    {
        int nLen = GetRandNum(nMIn, nMax);
        string strChars(nLen, '0');
        for (int i = 0; i < nLen; ++i)
        {
            strChars[i] = GetChar(bIsAccount);
        }
    
        return strChars;
    }
    
    
    int main()
    {
        // 生成20个账号&&密码
        for (int i = 0; i < 20; ++i)
        {
            cout << "账号: " << i << GetAccountNumOrPassWord(7,10, TRUE) << "  	密码: " << GetAccountNumOrPassWord(20, 25, FALSE) << endl;
        }
    
        getchar();
        return 0;
    }

  • 相关阅读:
    利用 Memory Dump Diagnostic for Java (MDD4J) 分析内存管理问题
    Google开源软负载seesaw
    Commit can not be set while enrolled in a transaction
    del_cursor 批量删除游标
    java api 批量数据库操作
    eclipse invalid zip archive lib
    less,more,view一个文件时中文可以正常显示,可是VI却显示乱码呢?
    10-13 Zuul面试点之Cookie和特殊头信息处理
    10-12 Zuul面试点之Hystrix降级处理
    10-11 Zuul面试点之Hystrix整合
  • 原文地址:https://www.cnblogs.com/DuanLaoYe/p/5465100.html
Copyright © 2011-2022 走看看