eZdia Forum Forum Index
eZdia Forum
A forum for eZdia lovers
www.eZdia.com

 FAQFAQ    RegisterRegister   Log inLog in 
The time now is Tue Feb 07, 2012 4:20 pm
eZdia Forum Forum Index
 ProfileProfile  UsergroupsUsergroups   Log in to check your private messagesLog in to check your private messages 
Random Number generation in PHP

 
Post new topic   Reply to topic    eZdia Forum Forum Index -> Web Development
View previous topic :: View next topic  
Author Message
rickb



Joined: 25 Apr 2009
Posts: 9

PostPosted: Sat Apr 25, 2009 8:29 pm    Post subject: Random Number generation in PHP Reply with quote

I would like to know how to generate random number in PHP.
Back to top
View user's profile Send private message
rickb



Joined: 25 Apr 2009
Posts: 9

PostPosted: Sat Apr 25, 2009 8:32 pm    Post subject: Reply with quote

I figured out that the answer was easy. For example
Code:


<srand>


generates the random number between 0 and 9.

Also

Code:


rand(1, 6)



generates random number between 1 and 6.
Back to top
View user's profile Send private message
Anubhav



Joined: 28 Apr 2009
Posts: 2

PostPosted: Tue Apr 28, 2009 11:43 am    Post subject: Reply Reply with quote

Hi, This is Anubhav
You can use "rnd" to generate random numbers.
Back to top
View user's profile Send private message
William James



Joined: 12 May 2009
Posts: 2

PostPosted: Tue May 12, 2009 11:36 am    Post subject: Re: Reply with quote

Hi,
By using "mt_rand" function u can generate random numbers easily.
Regards
Back to top
View user's profile Send private message
madhu2300



Joined: 30 May 2009
Posts: 25

PostPosted: Sun May 31, 2009 5:11 pm    Post subject: Reply with quote

This is the solution --

Definition: The rand () function is used to generate a random number in PHP. It can also be used to generate a random number within a specific range (for example a number between 10 and 30.) On a some platforms, Windows for example, if unspecified the largest number that will be generated is 32768, however you can set a specific range to include higher numbers.
Examples:

<php>
Back to top
View user's profile Send private message
havard



Joined: 04 Jun 2009
Posts: 6

PostPosted: Thu Jun 04, 2009 4:11 am    Post subject: Reply with quote

Let's do some code that will generate a random number in PHP.The rand () function is used to generate a random number in PHP. It can also be used to generate a random number within a specific range (for example a number between 10 and 30.)
On a some platforms, Windows for example, if unspecified the largest number that will be generated is 32768, however you can set a specific range to include higher numbers.
Examples:
<?
<php>
?>
_________________
http://ezdia.org
Back to top
View user's profile Send private message
Fnand



Joined: 28 Jun 2009
Posts: 36

PostPosted: Fri Jul 03, 2009 12:08 pm    Post subject: Reply with quote

hey here is how you can create a random number in php. as havard has said correctly we have to use the rand() function in order togenerate a random number.We can generate the random number in php by giving the code as below-
Rand () function to generate random number.
Rand () %9, generates random number from 0-9
Back to top
View user's profile Send private message
jitendra45



Joined: 04 Jul 2009
Posts: 26

PostPosted: Sat Jul 04, 2009 10:12 am    Post subject: generate random number Reply with quote

It can be done with the help of rand() in the code that we write. Also this rand() is existing in all the languages which is best to create random numbers.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    eZdia Forum Forum Index -> Web Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Po wer xed by php B B © 2001, 2005 php BB Group | A Forum Home |