So I have a list of the top 100 boys names in Ireland:
Here's my PHP:
<?php
$top100irishNames = <<<END
Jack
James
Daniel
Sean
Conor
Adam
Harry
Ryan
Dylan
Michael
Luke
Charlie
Liam
Oisin
Cian
Jamie
Thomas
Alex
Noah
Darragh
Patrick
Aaron
Cillian
Matthew
John
Nathan
David
Fionn
Evan
Ethan
Jake
Kyle
Rian
Ben
Max
Eoin
Tadhg
Finn
Callum
Samuel
Joshua
Rory
Jayden
Joseph
Tyler
Sam
Shane
Mark
Robert
Aidan
William
Ronan
Eoghan
Alexander
Leon
Cathal
Mason
Tom
Oliver
Andrew
Oscar
Ciaran
Bobby
Jacob
Senan
Rhys
Scott
Benjamin
Cormac
Kevin
Lucas
Alan
Donnacha
Jakub
Christopher
Filip
Killian
Josh
Alfie
Tommy
Ruairi
Odhran
Oran
Leo
Isaac
Dara
Jason
Zach
Martin
Peter
Brian
Danny
Niall
Tomas
Edward
Stephen
Logan
Kacper
Anthony
Billy
END;
$top100irishNames_arr=preg_split("/\n/",$top100irishNames);
for($i=0;$i<25;$i++){
echo getRandomWeightedElement($top100irishNames_arr)."\n";
}
function getRandomWeightedElement($arr) {
$rand = mt_rand(1, (int) sizeof($arr));
for ($i=0;$i<sizeof($arr);$i++) {
$rand -= $i;
if ($rand <= 0) {
return $arr[$i];
}
}
}
?>
Jack, James, Daniel, Sean, etc. should output a lot...
But here's some random output:
Ryan
Cian
Luke
Charlie
Harry
Luke
Harry
Charlie
Oisin
Ryan
Luke
Luke
Michael
Liam
Liam
Adam
Ryan
Oisin
Conor
Oisin
Liam
Oisin
Daniel
Adam
Oisin
I don't see any Jack/James/etc.?
I'm trying to have the sampler output the names at the beginning of the array most often, and the names at the end of the array least often.