FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[PHP] mt_rand or rand?





n0obie4life
http://php.net/rand
http://php.net/mt_rand

It seems to me that mt_rand works better than rand for my dynamic signature below.

( The MOTM, feel free to use it in your sig Wink ).

So, what should I be using?
roeenoy
rand() is the basic function to do it so why being usuall ?
polarBear
The mersenne twister algorithm is quite faster and, to me at least, more random -produces less colissions-, though it's practically the same if you don't need a MASSIVE source of entropy.

You could also use a combination of mt_rand, fibonacci sequence and prime numbers to increase the entropy source, to get better numbers, or make the script store the last 10 numbers somewhere, and recalculate a random number if it appears on that list.
BlackSkad
As it is stated on the php.net-site, mt_rand is a drop-in replacement for rand. They have the same result, but mt_rand is an better/faster way to get a random value.
Wherever you can, use mt_rand, I should say.
n0obie4life
Yeah, I did a comparison and my dynamic sig did load faster with mt_rand Wink..

And true, it's really more random. I don't get repeats.
Related topics
E-Cards with PHP & MySQL
Random page generator
How to make a Random code in PHP !
[php] Overwrite pre-made functions?
Two Scripts that I need!
PHP script trouble
Can't get strings to output correctly
Replacement of hexadecimal values in PHP string
Please help my crappy php skills need help
php / javascript script works in FireFox browser, but not IE
php 4
I want to output an img url from a random image script
Having browser not pull files from the cache.
Please Help! Spaces All Over Page
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.