写着玩的,见笑
#include "stdafx.h"
#include <stdio.h>
#include "windows.h"
#pragma comment(lib,"winmm.lib")
int main(int argc, char* argv[])
{
int RanNum;
int n1,n2;
int count;
char *buffer;
char ch;
//产生种子
srand((unsigned(timeGetTime())));
RanNum=rand();
n1=RanNum%10;
printf("随机数字%d\n",n1);
n1++;
buffer=(char *)VirtualAlloc(NULL,2*n1,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
memset((void *)buffer,0,2*n1);
for (count=0;count<(2*n1-1);count++)
{
RanNum=rand();
n2=RanNum%52;
printf("随机数字%d\n",n2);
if (n2>=26)
{
ch=n2&0x0F;
ch+=0x47; //'a'------'z'
}
else
{
ch=n2&0x0F;
ch+=0x41; //'A'-----'Z'
}
buffer[count]=ch;
}
printf("生成随机字符串:%s\n",buffer);
VirtualFree(buffer,2*n1,MEM_DECOMMIT);
return 0;
}
- 标 题:随机字符串生成函数
- 作 者:火影
- 时 间:2009-05-18 22:59
- 链 接:http://bbs.pediy.com/showthread.php?t=89204