|
|
|
| Web Hosting |
![]() ![]() |
Php Random Selector, whats the code |
Jul 21 2008, 12:21 PM
Post
#1
|
|
|
Premium Member Group: [HOSTED] Posts: 255 Joined: 17-July 08 From: Atlantis Member No.: 31,503 myCENTs:73.77 |
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? |
|
|
|
Jul 21 2008, 07:03 PM
Post
#2
|
|
|
Super Member Group: [HOSTED] Posts: 500 Joined: 5-November 06 Member No.: 17,016 myCENTs:79.88 |
QUOTE(khalilov @ Jul 21 2008, 08:21 PM) [snapback]125994[/snapback] 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://my2.php.net/rand All you need is to call the rand() function. If you want to generate a random number between 0 to x, then just call CODE rand(0, x); As for your random string, all you need is to extend the rand function a little bit CODE $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 |
|
|
|
Jul 25 2008, 03:30 AM
Post
#3
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 15 Joined: 25-July 08 Member No.: 31,646 |
QUOTE(khalilov @ Jul 21 2008, 08:21 AM) [snapback]125994[/snapback] 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. |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
11 | ViRuaL | 2,360 | 10th December 2008 - 10:14 PM Last post by: iG-nick |
|||
![]() |
3 | Sir Joe | 2,023 | 2nd December 2008 - 03:14 AM Last post by: iG-Ben and Hank |
|||
![]() |
13 | FirefoxRocks | 462 | 24th November 2008 - 03:54 AM Last post by: FirefoxRocks |
|||
![]() |
7 | eina | 374 | 20th November 2008 - 11:30 PM Last post by: tansqrx |
|||
![]() |
4 | Feelay | 433 | 8th May 2008 - 10:20 AM Last post by: Jared |
|||
![]() |
6 | sxyloverboy | 2,501 | 7th May 2008 - 03:34 PM Last post by: iGuest |
|||
![]() |
6 | soleimanian | 2,251 | 2nd May 2008 - 12:36 PM Last post by: iGuest |
|||
![]() |
4 | demolaynyc | 1,027 | 25th March 2007 - 05:35 PM Last post by: yordan |
|||
![]() |
2 | Vyoma | 2,741 | 14th October 2006 - 07:19 AM Last post by: Vyoma |
|||
![]() |
3 | pyost | 927 | 28th August 2006 - 09:26 PM Last post by: vhortex |
|||
![]() |
2 | laurenlovesyou | 640 | 28th June 2006 - 03:21 PM Last post by: austiniskoge |
|||
![]() |
0 | oval | 1,418 | 3rd May 2006 - 08:34 PM Last post by: oval |
|||
![]() |
0 | mark.smith.mvs | 461 | 30th November 2005 - 03:19 PM Last post by: mark.smith.mvs |
|||
![]() |
3 | Rejected | 1,747 | 15th September 2005 - 06:25 AM Last post by: jvizueta |
|||
![]() |
1 | amit | 1,555 | 22nd August 2005 - 04:47 PM Last post by: miCRoSCoPiC^eaRthLinG |
|||
|
Lo-Fi Version | Time is now: 8th January 2009 - 12:31 AM |
© 2009 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



Jul 21 2008, 12:21 PM




