基于硬件的随机数打造。通过修改字符串sss的初值来修改字符集。

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio( false );
    cin.tie( 0 );
    std::fstream s( "random.txt", std::fstream::binary | std::fstream::trunc | std::fstream::in | std::fstream::out );
    if ( !s.is_open() ) {
        cerr << "failed to open "
             << "random.txt" << endl;
    }
    random_device rd;
    unsigned int n, maxlength;
    string sss = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    cin >> n >> maxlength;
    std::uniform_int_distribution< unsigned int > dist( 0, sss.length() - 1 );
    while ( n-- ) {
        string now;
        for ( unsigned int i = 1; i <= maxlength; i++ ) {
            now += sss[dist( rd )];
        }
        s << now << endl;
    }
    return 0;
}
Last modification:March 2, 2021
如果您觉得我的文章有用,给颗糖糖吧~