HOME       >>       Programming

Php Random Selector whats the code


khalilov

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?


faulty.lee

Is there a PHP script that randomly selects a string from a list?example, the list is: 1-Pie
2-Balls
3-eggs
The 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

Mike gambino

Is there a PHP script that randomly selects a string from a list?example, the list is: 1-Pie
2-Balls
3-eggs
The 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.


VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.