June 20
string randomAlphanumericString(int length)
{
    import std.array : array;
    import std.ascii : letters, digits;
    import std.random : choice, Random, unpredictableSeed;
    import std.range : generate, take;
    import std.conv : to;

    auto rnd = Random(unpredictableSeed);
    auto symbols = array(letters ~ digits);

    return generate!({ return symbols.choice(rnd); }).take(length).to!string;
}
June 20

On Monday, 20 June 2022 at 11:49:24 UTC, greenbyte wrote:

>
string randomAlphanumericString(int length)
{
    import std.array : array;
    import std.ascii : letters, digits;
    import std.random : choice, Random, unpredictableSeed;
    import std.range : generate, take;
    import std.conv : to;

    auto rnd = Random(unpredictableSeed);
    auto symbols = array(letters ~ digits);

    return generate!({ return symbols.choice(rnd); }).take(length).to!string;
}

This works, but just a gentle reminder that this must not be used to generate secrets (passwords, tokens, IDs whose disclosure could be problematic...). std.random is not cryptographically secure and therefore not fit for any security-related purpose. If on the other hand you're just generating public IDs, delimiters, that sort of things, then there is absolutely no issue with doing it this way.