I have an array of campaigns, each campaign has a bid.
For example:
$campaigns[0] = array('id' => '1', 'url' => 'some url', 'bid' => '1.26');
$campaigns[1] = array('id' => '2', 'url' => 'some url', 'bid' => '1.20');
$campaigns[2] = array('id' => '2', 'url' => 'some url', 'bid' => '1.15');
$campaigns[3] = array('id' => '3', 'url' => 'some url', 'bid' => '1.05');
As of now I simply have the array sorted from highest bid to lowest. The thing is I would like to add some randomness to this. This is not necessarily a PHP question but rather an algorithm question.
After sorting the array from highest to lowest bid, I would like to go through it once more and randomize the elements slightly, so even the lowest bid can end up as the first element in the array sometimes, although not often.
Essentially after running the randomize taking into priority on the array 100 times, the expected results for the first item in the array should be something along the lines of:
ID - Occurences
1 - 60
2 - 25
3 - 11
3 - 4
Obviously this is just an example to give you an idea of what I'm trying to do, and this would vary from each trial run.
Does anyone have any suggestions on how I should do this?
Aucun commentaire:
Enregistrer un commentaire