Improving my random PHP script
Posted on 2009-03-29
Hey guys. I hope someone can help me out with this script, it has 3 flaws that I would like to improve :-) its a "random PHP code with priorities and maximum weight allowed". I want it to be able to show three 'random' items, but based on: priorities and weight, and a minimum and maximum weight allowed for all 3 combined items it should show.
So fx "Gyn". It could have a priority to show of 50, and a weight of 30. The maximum weight allowed should be 100, and the minimum weight allowed should be 90.
3 items that could show up would be then fx "Gyn" (30 weights, and with a high priority), "hels" (20 weights) and "part" (45 weights). Just as an example.
But there is 3 flaws in this code down below, that I hope someone will be able to help me out with. :-)
1) The priority for an item is the same as its weight, but instead they should be seperate. So it could have a priority of 60 and a weight of 40 fx.
2) This script, once it hits 3 randomly items that a weight greater than 100, stops working. It works fine with a random 3 items with a weight below 100, but when it hits 3 items with a combined weight of over 100 the script just loads and loads until it gives this error
"Fatal error: Maximum execution time of 30 seconds exceeded in /home6/distende/public_html/ran/dodosrangen.php on line 47"
3) The script has no minimum weight allowed at the moment. Its maximum weight allowed is 100, and it's minimum weight could be 80 fx.
Thanks alot for all your time!