Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Create random 3 digit number
Old 06-10-2005, 05:22 PM Create random 3 digit number
Unknown.

Posts: 1,693
Trades: 0
What I need to do is create a random 3 digit number.. for something im working on..

searched google but couldn't find much.. only thing I found was a way to create a random number but it ended up giving me 1 and 2 digit numbers aswell.. and I need a 3 digit number!

So if someone could help with a sample of the code that would be great.

Thanks
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-10-2005, 06:03 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
Did a search for "php random three digit number" on google and this was the very first result...

PHP Code:
<?php
/*  RandomDigit  1.0  --  Copyright  1998  by  Michael  A.  Smith  --  msmith@dn.net
This  function  returns  a  random  string  of  a  specified  number  of  digits
without  leading  zeros.  For  example,  if  three  digits  are  specified,  the
function  will  return  a  random  three-digit  number  from  100  to  999.  If  you
specify  an  eight-digit  string  you  will  not  get  numbers  with  fewer  than
eight  digits,  e.g.  376  or  6.  */

function  randomdigit($digits)  {  
      static  
$startseed  =  0;  
      if  (!
$startseed)  {
            
$startseed  =  (double)microtime()*getrandmax();  
            
srand($startseed);
      }
      
$range  =  8;
      
$start  =  1;
      
$i  =  1;
      while  (
$i<$digits)  {
            
$range  =  $range  .  9;
            
$start  =  $start  .  0;
            
$i++;
      }
      return  (
rand()%$range+$start);  
}
?>
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 06-10-2005, 06:35 PM
Unknown.

Posts: 1,693
Trades: 0
I must have been using the wrong keywords

Thanks anyway!
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 06-10-2005, 06:39 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
No problem, I do it too at times.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 06-10-2005, 07:09 PM
Monkeon's Avatar
Skilled Talker

Posts: 59
Trades: 0
This also generates random 3 digit number

PHP Code:
<?

$random 
rand(100999);

echo 
"$random";

?>
__________________

Please login or register to view this content. Registration is FREE
FREE Online Dating!
Meet your perfect match online right now!
Monkeon is offline
Reply With Quote
View Public Profile
 
Old 06-10-2005, 09:26 PM
Unknown.

Posts: 1,693
Trades: 0
thanks
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Create random 3 digit number
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23778 seconds with 12 queries