On Tuesday, 25 January 2022 at 11:50:08 UTC, vit wrote:


thanks. problem solved (providing all parameters are of the same type).

// ---

module test;
import std;

auto RandomChoice(R...)(R r)
{
    auto rnd = MinstdRand0(unpredictableSeed);
    return only(r).randomSample(1, rnd).front;
}

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

//writeln( RandomChoice("typeA", 5, 100.14) ); // nope. they all need to be of the same type. writeln( RandomChoice("typeA", 5.to!string, 100.14.to!string) );
}

//--

Reply via email to