khalilov 0 Report post Posted July 21, 2008 Is there a PHP script that randomly selects a string from a list?example, the list is: 1-Pie 2-Balls 3-eggsThe script would view a random word from those 3 every time i run it.Also is there a function that gives a random number between 0 and a number i select? Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted July 21, 2008 Is there a PHP script that randomly selects a string from a list?example, the list is: 1-Pie 2-Balls 3-eggsThe script would view a random word from those 3 every time i run it.Also is there a function that gives a random number between 0 and a number i select?Here is your random number generator -> http://forums.xisto.com/no_longer_exists/All you need is to call the rand() function. If you want to generate a random number between 0 to x, then just call rand(0, x); As for your random string, all you need is to extend the rand function a little bit$strCol = array("Pie", "Balls", "eggs");$i = rand(0, count($strCol) -1);echo $strCol[$i];This is how it works. First you create an array of string for your list. Then calling rand and passing it 0 as min, and max would be array count - 1. You need to minus 1 because index is zero based. After that just index your array using the random number you got. With this setup, you can easily add more string to your array and the rest is taken care of automatically Share this post Link to post Share on other sites
Mike gambino 0 Report post Posted July 25, 2008 Is there a PHP script that randomly selects a string from a list?example, the list is: 1-Pie 2-Balls 3-eggsThe script would view a random word from those 3 every time i run it.Also is there a function that gives a random number between 0 and a number i select?wow that's cool. I would like that but on my game website would be a lot more advanced than that. I have a LONG code for that one but it is hard to type it down for on thing. right now I have to get my website fully done. I will let people look at my website when it is done though. Share this post Link to post Share on other sites