H I O X INDIA
FREE PHP Topics
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

PHP Topics
Introduction
Common Header
Random Number
Type
Form Variables
Date and Time
File Handling
Error Handling
DB Size
PHP Mail
String Tokens
Running PHP from JS
Array To JS
Array to PHP
Encryption
Ask Your Doubts
Feedback





Random Number in PHP and Javascript


Topic

How to create or generate random number in php?
creating or generating random number using javascript?



Explanation

Follow the steps to create Random Numbers

Getting Random Numbers in PHP:
Its very easy to get random numbers in php too.
PHP gives a method called "rand()".

Using the method we can get random numbers.
Calling rand() will return values between 0 and RAND_MAX

e.g:
<?php
$numb = rand(); //Here we create a random number
echo($numb);
?>

Result: 194165421

So now we have to get values between x to y say 50 to 66.
It can be achieved by following the example
e.g:
<?php
$numb = rand(50,66); //Here we create a random number between 50 and 66
echo($numb);
?>

Result: 54

Getting Random Numbers in javascript:
Its very easy to get random numbers in javascript.
javascript gives a method called "random()".

Using the method we can get random numbers.
Calling Math.random() will return values between 0 and 1

e.g:
<script>
var numb = random(); //Here we create a random number
document.write(numb);
</script>

Result:

So now we have to get values between x to y say 0 to 66.
It can be achieved by following the example
e.g:
<script>
var numb = Math.random(); //Here we create a random number e.g: .23xxxx
numb = numb*66; //Here we multiply the number by 66. e.g: the value will convert to 15.xxxx
numb = Math.round(numb); //Now we round of the value. e.g: the value will be rounded to 15
document.write(numb); //So we have got a random number inbetween 0 and 66

</script>

Result:




others


privacypolicy     licence     sitemap
(c) copyright, 2004 hioxindia.com