c代码生成器源码(c语言代码自动生成)
本文目录一览:
C语言随机数生成器代码解析
在C语言中,欲求正整数a到b(a b)间的数的语句是:
rand()%(b - a) + a;
假如a = 50,b = 100,则
rand()%50 + 50;
因为 0 ≤ rand()%50 ≤ 49,所以rand()%50 + 50 的范围是: 50 ~ 99
跪求C语言的随机数生成器的头文件代码
这题不是让自己根据给出的算法实现么?
给你两篇参考文献吧:
C语言产生随机数:
rand ( ) 和 srand ( )【C语言库函数源代码】:
如何用C语言编一个密码生成器
C语言实现密码生成器,参考代码如下:
#include
#include
#include
//const char lower_chars[] = "abcdefghijklmnopqrstuvwxyz";
//const char upper_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//const char number_chars[] = "0123456789";
const char lower_chars[] = "abcdefghijkmnpqrstuvwxyz"; // no l or o
const char upper_chars[] = "ABCDEFGHJKLMNPQRSTUVWXYZ"; // no I or O
const char number_chars[] = "23456789"; // no 1 or 0
const char special_chars[] = "!@#$%^*()-=_+[]{};:'\",.?/";
const int _ks_pass_len = 17;
void mkpass(char pass[_ks_pass_len+1])
{
int i = 0, j = 0, k = 0,n = 0;
n = _ks_pass_len/4;
for (; i n; i++)
{
pass[i] = lower_chars[rand()%(strlen(lower_chars))];
pass[i+n] = upper_chars[rand()%(strlen(upper_chars))];
pass[i+2*n] = number_chars[rand()%(strlen(number_chars))];
pass[i+3*n] = special_chars[rand()%(strlen(special_chars))];
}
j = _ks_pass_len - 4*n;
for (i = 0; ij; i#43;#43;) {
pass[i+4*n] = special_chars[rand()%(strlen(special_chars))];
}
//字符乱序
for (i = 0; i 32; i++)
{
j = rand()%(_ks_pass_len);
k = pass[j];
pass[j] = pass[i%_ks_pass_len];
pass[i%_ks_pass_len] = k;
}
pass[_ks_pass_len] = '\0';
}
int _tmain(int argc, _TCHAR* argv[])
{
srand(time(0));
char szPass[_ks_pass_len+1];
for (int i=0; i16; i++)
{
mkpass(szPass);
printf("%s\n",szPass);
}
return 0;
}j; i#43;#43;)