sample

sample
(
T
)
(
ref Random rnd
,)

Return Value

Type: auto

A random sample of the type T. TODO: Use direct field setting for T only when __traits(isPOD, T) is true otherwise use __traits(getOverloads, T, "__ctor"). Test on std.json.JSONValue.

Examples

scalar

    auto rnd = Random(42);
	auto s = rnd.sample!ubyte;

char[]

    auto rnd = Random(42);
	foreach (_; 0 .. 100) {
		auto s = rnd.sample!(char[])(Format(Span(0,10)));
		// dbg(s);
	}

struct

    auto rnd = Random(42);
	struct S { byte x, y;}
	struct T { short a, b; ushort c, d; S s; }
	struct U { int a, b; uint c, d; T t; int[] ia; }
	auto s = rnd.sample!U;
	// dbg(s);

Meta