On Tuesday, 25 January 2022 at 22:07:43 UTC, Ali Çehreli wrote:


thanks. makes it even shorter and simpler :-)

// --

module test;
@safe:

import std;

auto RandomChoice(R...)(R r)
{
    auto rnd = MinstdRand0(unpredictableSeed);
    return only(r).choice(rnd);
}

void main()
{
    writeln( RandomChoice("typeA", "typeB", "typeC") );
    writeln( RandomChoice(5, 8, 2) );
    writeln( RandomChoice(1.3, 5.09, 8, 2) );
    writeln( RandomChoice(100.05, 110.8, 109.54) );

    //writeln( RandomChoice("typeA", 5, 100.14) );
    // nope. some issue with mixing strings with numeric types

writeln( RandomChoice("typeA", 5.to!string, 100.14.to!string) );
    // NOTE: This registers with -profile=gc
}

// --


Reply via email to