#pragma
once
#define RdAllType 0x07 // ′óD?D′oíêy×?
#define RdNum 0x01 // êy×?
#define RdLowercase 0x02 // D?D′
#define RdUppercase 0x04 // ′óD′
static TCHAR szAllChar[] = _T( " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 " );
bool fnRandomString( const int nLeng, TCHAR * RandStringInput, const int nType);
// 注释用了中文,插件粘贴对中文支持不好:
#define RdAllType 0x07 // 大小写和数字
#define RdNum 0x01 // 数字
#define RdLowercase 0x02 // 小写
#define RdUppercase 0x04 // 大写
#define RdAllType 0x07 // ′óD?D′oíêy×?
#define RdNum 0x01 // êy×?
#define RdLowercase 0x02 // D?D′
#define RdUppercase 0x04 // ′óD′
static TCHAR szAllChar[] = _T( " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 " );
bool fnRandomString( const int nLeng, TCHAR * RandStringInput, const int nType);
// 注释用了中文,插件粘贴对中文支持不好:
#define RdAllType 0x07 // 大小写和数字
#define RdNum 0x01 // 数字
#define RdLowercase 0x02 // 小写
#define RdUppercase 0x04 // 大写
#include
"
stdafx.h
"
#include " RandomString.h "
#include < stdlib.h >
#include < time.h >
bool fnRandomString( const int nLeng, TCHAR * RandStringInput, const int nType)
{
if ( 0 == nLeng)
{
return true ;
}
if (nLeng < 0 )
{
return false ;
}
srand((unsigned int )time(NULL));
bool bRet = false ;
int nMin = 0 ;
int nMax = 62 ;
switch (nType & RdAllType)
{
case RdAllType:
break ;
case RdNum:
nMin = 52 ;
break ;
case RdNum | RdLowercase:
nMin = 26 ;
break ;
case RdNum | RdUppercase:
nMin = 26 ;
break ;
case RdUppercase:
nMax = 25 ;
break ;
case RdUppercase | RdLowercase:
nMax = 51 ;
break ;
case RdLowercase:
nMin = 26 ;
nMax = 51 ;
break ;
default :
return false ;
break ;
}
int nRange = nMax - nMin;
if (nType == (RdNum | RdUppercase))
{
int nNum = 0 ;
for ( int t = 0 ; t <= nLeng; t ++ )
{
nNum = nMin + rand() % nRange;
if (nNum < 52 )
{
nNum -= 26 ;
}
RandStringInput[t] = szAllChar[nNum];
}
}
else
{
for ( int t = 0 ; t <= nLeng; t ++ )
{
RandStringInput[t] = szAllChar[nMin + rand() % nRange];
}
}
// int tt = 0;
// while (RandStringInput[tt])
// {
// printf("%c ", RandStringInput[tt]);
// tt++;
// }
return true ;
}
#include " RandomString.h "
#include < stdlib.h >
#include < time.h >
bool fnRandomString( const int nLeng, TCHAR * RandStringInput, const int nType)
{
if ( 0 == nLeng)
{
return true ;
}
if (nLeng < 0 )
{
return false ;
}
srand((unsigned int )time(NULL));
bool bRet = false ;
int nMin = 0 ;
int nMax = 62 ;
switch (nType & RdAllType)
{
case RdAllType:
break ;
case RdNum:
nMin = 52 ;
break ;
case RdNum | RdLowercase:
nMin = 26 ;
break ;
case RdNum | RdUppercase:
nMin = 26 ;
break ;
case RdUppercase:
nMax = 25 ;
break ;
case RdUppercase | RdLowercase:
nMax = 51 ;
break ;
case RdLowercase:
nMin = 26 ;
nMax = 51 ;
break ;
default :
return false ;
break ;
}
int nRange = nMax - nMin;
if (nType == (RdNum | RdUppercase))
{
int nNum = 0 ;
for ( int t = 0 ; t <= nLeng; t ++ )
{
nNum = nMin + rand() % nRange;
if (nNum < 52 )
{
nNum -= 26 ;
}
RandStringInput[t] = szAllChar[nNum];
}
}
else
{
for ( int t = 0 ; t <= nLeng; t ++ )
{
RandStringInput[t] = szAllChar[nMin + rand() % nRange];
}
}
// int tt = 0;
// while (RandStringInput[tt])
// {
// printf("%c ", RandStringInput[tt]);
// tt++;
// }
return true ;
}
VS2010下编译通过。