I am mainly posting this code here because I keep misplacing it on my own hard drive. And that usually leads to it being forgotten and lost… if there is anything confusing here, don’t hesitate to ask in the comments–I wrote this a bit fast.
What is a weighted random value? Take a look at this (poor) example…
You have an array of shades of grey in hex:
$colors = array('000','1f1f1f','3f3f3f','666','999','ccc','eaeaea','f0f0f0');
You have a table of data and you want to give each row a random background color that is one of those shades.
Simple, right? echo $colors[array_rand($colors)];
But, what if you want to return the colors around #999 more often than the rest? » Read more: Getting a weighted random value in PHP