468,243 Members | 2,038 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,243 developers. It's quick & easy.

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.

Jul 17 '05 #1
2 1938
vishal wrote:
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


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
Jul 17 '05 #2
*** vishal escribió/wrote (25 Mar 2005 00:13:17 -0800):
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.


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
--
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Laphan | last post: by
15 posts views Thread by John Cassidy | last post: by
12 posts views Thread by Jim Michaels | last post: by
20 posts views Thread by jjmillertime | last post: by
24 posts views Thread by pereges | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.