774 snippets from 1587 members, and growing!
|
login
|
join
about
bytebin
members
tags
snippets
join
Snippets
Submit a Snippet
Search Snippets
New Snippets
Top Snippets
Top Tags
PHP
(138)
JavaScript
(125)
Java
(66)
VBSCRIPT
(58)
String
(44)
CSS
(31)
CSharp
(28)
File
(28)
HTML
(27)
mysql
(25)
C
(24)
VB.NET
(24)
python
(24)
CPlusPlus
(23)
groovy
(23)
New Snippets
Clean PHP Templat...
PHP/MySQL impleme...
Analyte - Easy to...
Easy SQLite inter...
Very lightweight ...
AutoComplete plug...
AutoComplete plug...
Connection Java -...
View PostgreSql
Store Procedure
Venture Capital Jobs
New Members
me
jamesmcm
Can
Kelmi
ysg
dannymo2
chorny
wallie
Hackdemian
impomatic
Top Members
dannyboy
sundaramkumar
mattrmiller
Pio
i_kenneth
ASmith
ctiggerf
sehrgut
bertheymans
SCoon
Home
/
Snippets
/
Random String Generator
Random String Generator
Snippet Menu
Revisions
Comments
Related Snippets
Add to Favorites
Email Snippet
Download Snippet
Print Snippet
Blog Snippet
snippet
|
revisions
|
comments
|
related
|
Add to Favorites
|
email
download
|
print
|
blog it
5
Fri. Oct. 14th, 2005 4:49 PM
1 of 1
lilleman
PHP
|
Random
|
String
1 comments
Random String Generato
<?php
function
getRandomString
(
$chars
,
$length
)
{
for
(
$string
=
null
;
strlen
(
$string
)
<
$length
;
$string
.=
$chars
{
mt_rand
(
0
,
strlen
(
$chars
)
-1
)
}
)
;
return
$string
;
}
?>
Erik Riklund
phofer.com
Comments
New Comment
Good
Wed. Apr. 2nd, 2008 3:34 PM
sehrgut
Probably the most correct of similar implementations here. I'd make one change, and that is to change the function prototype as below.
I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?
function
getRandomString
(
$length
,
$chars
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
)
Reply
New Comment
Voting
Votes Up
dannyboy
i_kenneth
morad
Pio
SecondV
sehrgut
sundaramkumar
Votes Down
ASmith
wiz1705
I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?