Tip: After the article is written, the table of contents can be automatically generated. For how to generate it, please refer to the help document on the right.
Preface
Randomly generate letters or strings using C/C++ language
text
#define _CRT_SECURE_NO_WARNINGS //防止系统报函数不安全
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
for (int i = 0; i < 100; i++)
{
ch = 'a' + rand() % 26; //随机生成字母,这里采用对26取余数,得到的余数在0~25之间
}
}
# 总结
虽然随机生成字符串的思想比较简单,但是我们要把理解巧用对26取余数的比较巧妙的思路。