Skip to content

Instantly share code, notes, and snippets.

@asad01304
Created August 10, 2015 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asad01304/55dd9339376434fefdf6 to your computer and use it in GitHub Desktop.
Save asad01304/55dd9339376434fefdf6 to your computer and use it in GitHub Desktop.
<?php
$items = array(
'original' => 50,
'v1' => 20,
'v2' => 10,
'v3' => 20,
);
$rand = rand(0,100);
$sum = 0;
foreach($items as $id => $item){
$sum += $item;
if($rand <= $sum){
echo "$id => $item \n";
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment