Connecting Tech Pros Worldwide Help | Site Map

how to generate random number

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:17 PM
vishal
Guest
 
Posts: n/a
Default how to generate random number

hi

i want to generate a string which contains 5 characters and all 5
characters are randomly generated means it is not fixed that which
string i will get after i execute function.

so tell me random number generation in php

thxs in advance.


  #2  
Old July 17th, 2005, 12:17 PM
Chris Hope
Guest
 
Posts: n/a
Default Re: how to generate random number

vishal wrote:
[color=blue]
> i want to generate a string which contains 5 characters and all 5
> characters are randomly generated means it is not fixed that which
> string i will get after i execute function.
>
> so tell me random number generation in php[/color]

Random number generating function manual page: http://www.php.net/rand

To get your 5 character string you'll want to do something along the
lines of:

$x = '';
for($i = 0; $i < 5; $i++) {
$x .= chr(rand(97, 122));
}

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
  #3  
Old July 17th, 2005, 12:17 PM
Alvaro G. Vicario
Guest
 
Posts: n/a
Default Re: how to generate random number

*** vishal escribió/wrote (25 Mar 2005 00:13:17 -0800):[color=blue]
> i want to generate a string which contains 5 characters and all 5
> characters are randomly generated means it is not fixed that which
> string i will get after i execute function.[/color]

Your function is mt_rand(). The manual page includes some user comments you
can just copy & paste. Don't forget to generate a 'random' seed with
mt_srand().

--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ No envíes tu dudas a mi correo, publícalas en el grupo
-+ Do not send me your questions, post them to the group
--
 

Bookmarks

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.