实现如下:#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;
实现如下: