C语言如何生成随机数字和随机数字加字母的组合案例?
- 内容介绍
- 文章标签
- 相关推荐
本文共计450个文字,预计阅读时间需要2分钟。
我尽量简洁改写原文,不超过100字:不多说,直接看代码吧!
我就废话不多说了,大家还是直接看代码吧~
#include <time.h> #include <sys/timeb.h> void MainWindow::slot_clicked() { QString strRand; int length = 32; QString strTmp = "1234567890QWERTYUIOPASDFGHJKLZXCVBNM"; struct timeb timer; ftime(&timer); srand(timer.time * 1000 + timer.millitm);//毫秒种子 for(int i = 0; i < length; i++ ) { int j = rand()%35; strRand += strTmp.at(j); } qDebug() << strRand;
补充知识:C/C++生成随机数字符串(错误方法和正确方法)
先说错误的方法。生成的10个随机数是一样的。
本文共计450个文字,预计阅读时间需要2分钟。
我尽量简洁改写原文,不超过100字:不多说,直接看代码吧!
我就废话不多说了,大家还是直接看代码吧~
#include <time.h> #include <sys/timeb.h> void MainWindow::slot_clicked() { QString strRand; int length = 32; QString strTmp = "1234567890QWERTYUIOPASDFGHJKLZXCVBNM"; struct timeb timer; ftime(&timer); srand(timer.time * 1000 + timer.millitm);//毫秒种子 for(int i = 0; i < length; i++ ) { int j = rand()%35; strRand += strTmp.at(j); } qDebug() << strRand;
补充知识:C/C++生成随机数字符串(错误方法和正确方法)
先说错误的方法。生成的10个随机数是一样的。

