-
Notifications
You must be signed in to change notification settings - Fork 16
nspl\rnd
Ihor Burlachenko edited this page May 19, 2016
·
1 revision
Helps to pick random items from sequences of data
Returns a random item from a non-empty sequence
Returns a random item from a non-empty sequence of items with associated weights presented as pairs (item, weight)
use function \nspl\rnd\weightedChoice;
use function \nspl\a\pairs;
$nextPet = weightedChoice([['cat', 20], ['hamster', 30], ['dog', 50]]);
$nextFavouriteColor = weightedChoice(pairs(array(
'red' => 0.2,
'green' => 0.3,
'blue' => 0.5,
)));
Returns a k length list of unique items chosen from the population sequence
Check more \nspl\rnd
examples here.