Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Part 2.
- * Now there are two image arrays with different "weights", X and Y. Update your function so there is an X/(X+Y)% chance that
- * each image in the subset is selected from the first array, and a Y/(X+Y)% chance that the image is selected from the second array.
- * The returned subset should still be 1 dimensional, as in part 2.
- * Picking unique images is more important than the weights. i.e. if the subset isn't filled and there are no more images available in X
- * the remaining slots should be drawn exclusively from Y, and vice versa.
- * */
- $xImages = array('weight' => 3, 'images' => array('x1.jpg', 'x2.jpg', 'x3.jpg', 'x4.jpg', 'x5.jpg', 'x6.jpg')); //75%
- $yImages = array('weight' => 1, 'images' => array('y1.jpg', 'y2.jpg', 'y3.jpg', 'y4.jpg', 'y5.jpg', 'y6.jpg')); //25%
- $images = array($xImages, $yImages);
- $imageSetWeighted = selectWeighted($images, 6);
- echo '6: <pre>' . print_r($imageSetWeighted, true) . '</pre>';
- $imageSetWeighted = selectWeighted($images, 8);
- echo '8: <pre>' . print_r($imageSetWeighted, true) . '</pre>';
- $imageSetWeighted = selectWeighted($images, 16);
- echo '16: <pre>' . print_r($imageSetWeighted, true) . '</pre>';
- function selectWeighted($images, $number) {
- }
Add Comment
Please, Sign In to add comment