News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Jonathan Street's Blog:
Random thoughts on random strings
July 03, 2008 @ 07:58:33

On his blog, Jonathan Street has posted some "random thoughts" on generating random (or not so random) strings in PHP.

Humans are astoundingly bad at being random and I just slapped the keyboard a few times until I felt I had the required 16 characters. Writing some code to produce a fairly random string is incredibly easy. I've easily done it a dozen times or more. Though only because it is easier to re-write it than to find where I put the last one

He gives two examples that work, but aren't the best possibilities for making truly random strings - one using mt_rand to select a random character from a string and the other using the same idea but instead using the char() function to replace the string of characters.

His other examples include the use of the uniqid function with the more_entropy setting enabled and an md5 or sha1 hash (for which he gives positives and negtives).

1 comment voice your opinion now!
random string mtrand md5 sha1 chr uniqid moreentropy


blog comments powered by Disqus

Similar Posts

Edd Mann: Reversing a Unicode String in PHP using UTF-16BE/LE

Derick Rethans' Blog: Random Bugs and Testing RCs

PHPBuilder.com: An introduction to PEAR's Validate package

NetTuts.com: Refactoring Legacy Code: Part 2 - Magic Strings & Constants

Ryan Malesevich's Blog: MD5 to SHA-1 in PHP and MySQL (Part 1)


Community Events





Don't see your event here?
Let us know!


symfony artisanfiles release series introduction conference security tool library voicesoftheelephpant community composer opinion version interview framework podcast language laravel list

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework