pickAndCall

Calls a function according to a probability

bool
pickAndCall
(
T
Fun
A...
)
(
T t
,
Fun fun
,
auto ref A a
)
if (
isNumeric!T &&
isCallable!Fun
&&
is(ReturnType!Fun == void)
)

Parameters

t T

The chance to call, in percentage.

fun Fun

The function to call. It must be a void function.

a A

The variadic argument passed to fun.

Return Value

Type: bool

false if no luck.

Examples

uint cnt;
bool test;
void foo(uint param0, out bool param1) @safe
{
	cnt += param0;
	param1 = true;
}
foreach(immutable i; 0 .. 100)
	pickAndCall!(double)(75.0, &foo, 1, test);
assert(cnt > 25);
assert(test);
cnt = 0;
test = false;
foreach(immutable i; 0 .. 100)
	pickAndCall!(byte)(0, &foo, 1, test);
assert(cnt == 0);
assert(!test);

Meta