Re: replace %rand[x]-[y]% macro in string with random string

From: Date: Tue, 02 Dec 2003 23:56:28 +0000
Subject: Re: replace %rand[x]-[y]% macro in string with random string
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-171613@lists.php.net to get a copy of this message
On Tue, 2003-12-02 at 18:33, Richard Davey wrote: > Hello Daniel, > > Tuesday, December 2, 2003, 10:46:33 PM, you wrote: > > dh> For generation of a random string with length 1.000.000 it takes about > dh> 13 seconds on my xp 1600+.. that's quite a lot, imho, so suggestions > dh> are very welcome.. > I missed the original post, and I'm too lazy to go looking, but the following code runs in approx. 2.75 seconds on my Athlon 2400 running linux: $chars = '0123456789' .'abcdefghijklmnopqrstuvwxyz' .'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charArray = array(); for( $i = 0; $i < 1000000; $i++ ) { $charArray[] = $chars[rand( 0, 61 )]; } It's runs much faster than using a .= style of string creation. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#171613) next »