Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #27052 : rand() returns easily predictable numbers
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 29th December 19:13
php-bugs
External User
 
Posts: 1
Default #27052 : rand() returns easily predictable numbers


From: webmaster at armondc dot com
Operating system: Windows 2000 Professional
PHP version: 4.3.4
PHP Bug Type: Unknown/Other Function
Bug description: rand() returns easily predictable numbers

Description:
------------
I'm not sure if this is a very major problem, or even a bug, but here
goes:

It seems rand() on Windows is very predictable.

I've tried it on 2 Windows Systems, and they were both predictable. It
showed a breif unpredictable segment, then followed by the same string of
characters over and over, and finally a few more unpredictable
characters.

I tried this on a FreeBSD 5.2 System, and it was unpreditable enough.
Seems to be a windows-only problem.

I also noticed bug#11108 - It seems similar, but the submitter was using
his own seeds, and I am using without.

Reproduce code:
---------------
<?php
// This will reproduce the problem
// on windows
for($x = 0; $x < 500; $x++) {
echo chr((rand()%32)+65);
}

// This is a quick-fix, but
// goes agaist the do***entation's
// 'no need for srand()'
for($x = 0; $x < 500; $x++) {
srand(hexdec(substr(md5(microtime()), 0, 8)));
echo chr((rand()%32)+65);
}

?>

Expected result:
----------------
Something a bit random like:

HEOSITFS[ZYH_EVIVVXSLCWRHHC_]_L^PIBTC\TXPBWQLCM^VZSU`UHOG[\VF[KCDGFZM^Q\IG^KAIYPIYBSBIMGHXIBMPHLY\OAZMYAZPJ_`D`F \X\QXR[GP]DQLRHMYIOERBMEKBDJMJPN]J\\KPES^EGRKKO^S[`XL\SSHQXOYQU_JDMM`ZEUEOQOYMHJPYDTRRU_URHYJGXRQYDY ADD]OBVUGC^GGSXPRJJAOAKRAYYN^Q\`XFQJNOWQKAJBFONFXNDZFF IMYRL`ROH^]IM_MINJI\MJJAVG`]_B_EAV`C\O_\DHCHLX_NIO`U^KMJF\`K]VZDOZ_FAWCZC_IQK^[NTPZCC]XEFZ[`\AG[PV^XLPRYVAS]ZPH`^WAXYAZYGK_M_QK`F]PRMP^BBPTRV^KV_VDOLFIM]WQNHVF^DYWGGSGLJ_ZMODG[Z_AAXBYD^FS\MITLZESC`DXLH]NWNIVWZZMVMSXFQMG[O[W[YSPVMTQLHD

Actual result:
--------------
An easily spotted pattern:

]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\

--
Edit bug report at http://bugs.php.net/?id=27052&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27052&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27052&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27052&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27052&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27052&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27052&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27052&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27052&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27052&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27052&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27052&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27052&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27052&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27052&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27052&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27052&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27052&r=float
  Reply With Quote


  sponsored links


2 29th December 19:13
php-bugs
External User
 
Posts: 1
Default #27052 : rand() returns easily predictable numbers


ID: 27052
User updated by: webmaster at armondc dot com
Reported By: webmaster at armondc dot com
Status: Open
Bug Type: Unknown/Other Function
Operating System: Windows 2000 Professional
PHP Version: 4.3.4
New Comment:

On the "actual result" its not as easily spotted without wrapping.
This should give a better picture:

]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\


Previous Comments:
------------------------------------------------------------------------

[2004-01-26 15:53:26] webmaster at armondc dot com

Description:
------------
I'm not sure if this is a very major problem, or even a bug, but here
goes:

It seems rand() on Windows is very predictable.

I've tried it on 2 Windows Systems, and they were both predictable. It
showed a breif unpredictable segment, then followed by the same string
of characters over and over, and finally a few more unpredictable
characters.

I tried this on a FreeBSD 5.2 System, and it was unpreditable enough.
Seems to be a windows-only problem.

I also noticed bug#11108 - It seems similar, but the submitter was
using his own seeds, and I am using without.

Reproduce code:
---------------
<?php
// This will reproduce the problem
// on windows
for($x = 0; $x < 500; $x++) {
echo chr((rand()%32)+65);
}

// This is a quick-fix, but
// goes agaist the do***entation's
// 'no need for srand()'
for($x = 0; $x < 500; $x++) {
srand(hexdec(substr(md5(microtime()), 0, 8)));
echo chr((rand()%32)+65);
}

?>

Expected result:
----------------
Something a bit random like:

HEOSITFS[ZYH_EVIVVXSLCWRHHC_]_L^PIBTC\TXPBWQLCM^VZSU`UHOG[\VF[KCDGFZM^Q\IG^KAIYPIYBSBIMGHXIBMPHLY\OAZMYAZPJ_`D`F \X\QXR[GP]DQLRHMYIOERBMEKBDJMJPN]J\\KPES^EGRKKO^S[`XL\SSHQXOYQU_JDMM`ZEUEOQOYMHJPYDTRRU_URHYJGXRQYDY ADD]OBVUGC^GGSXPRJJAOAKRAYYN^Q\`XFQJNOWQKAJBFONFXNDZFF IMYRL`ROH^]IM_MINJI\MJJAVG`]_B_EAV`C\O_\DHCHLX_NIO`U^KMJF\`K]VZDOZ_FAWCZC_IQK^[NTPZCC]XEFZ[`\AG[PV^XLPRYVAS]ZPH`^WAXYAZYGK_M_QK`F]PRMP^BBPTRV^KV_VDOLFIM]WQNHVF^DYWGGSGLJ_ZMODG[Z_AAXBYD^FS\MITLZESC`DXLH]NWNIVWZZMVMSXFQMG[O[W[YSPVMTQLHD

Actual result:
--------------
An easily spotted pattern:

]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=27052&edit=1
  Reply With Quote
3 29th December 19:13
External User
 
Posts: 1
Default #27052 : rand() returns easily predictable numbers


ID: 27052
Updated by: sniper@php.net
Reported By: webmaster at armondc dot com
-Status: Open
+Status: Feedback
-Bug Type: Unknown/Other Function
+Bug Type: Math related
Operating System: Windows 2000 Professional
PHP Version: 4.3.4
New Comment:

Please try using this CVS snapshot:

http://snaps.php.net/php4-STABLE-latest.tar.gz

For Windows:

http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Some rand() related bugs have already been fixed..

Previous Comments:
------------------------------------------------------------------------

[2004-01-26 15:56:22] webmaster at armondc dot com

On the "actual result" its not as easily spotted without wrapping.
This should give a better picture:

]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\

------------------------------------------------------------------------

[2004-01-26 15:53:26] webmaster at armondc dot com

Description:
------------
I'm not sure if this is a very major problem, or even a bug, but here
goes:

It seems rand() on Windows is very predictable.

I've tried it on 2 Windows Systems, and they were both predictable. It
showed a breif unpredictable segment, then followed by the same string
of characters over and over, and finally a few more unpredictable
characters.

I tried this on a FreeBSD 5.2 System, and it was unpreditable enough.
Seems to be a windows-only problem.

I also noticed bug#11108 - It seems similar, but the submitter was
using his own seeds, and I am using without.

Reproduce code:
---------------
<?php
// This will reproduce the problem
// on windows
for($x = 0; $x < 500; $x++) {
echo chr((rand()%32)+65);
}

// This is a quick-fix, but
// goes agaist the do***entation's
// 'no need for srand()'
for($x = 0; $x < 500; $x++) {
srand(hexdec(substr(md5(microtime()), 0, 8)));
echo chr((rand()%32)+65);
}

?>

Expected result:
----------------
Something a bit random like:

HEOSITFS[ZYH_EVIVVXSLCWRHHC_]_L^PIBTC\TXPBWQLCM^VZSU`UHOG[\VF[KCDGFZM^Q\IG^KAIYPIYBSBIMGHXIBMPHLY\OAZMYAZPJ_`D`F \X\QXR[GP]DQLRHMYIOERBMEKBDJMJPN]J\\KPES^EGRKKO^S[`XL\SSHQXOYQU_JDMM`ZEUEOQOYMHJPYDTRRU_URHYJGXRQYDY ADD]OBVUGC^GGSXPRJJAOAKRAYYN^Q\`XFQJNOWQKAJBFONFXNDZFF IMYRL`ROH^]IM_MINJI\MJJAVG`]_B_EAV`C\O_\DHCHLX_NIO`U^KMJF\`K]VZDOZ_FAWCZC_IQK^[NTPZCC]XEFZ[`\AG[PV^XLPRYVAS]ZPH`^WAXYAZYGK_M_QK`F]PRMP^BBPTRV^KV_VDOLFIM]WQNHVF^DYWGGSGLJ_ZMODG[Z_AAXBYD^FS\MITLZESC`DXLH]NWNIVWZZMVMSXFQMG[O[W[YSPVMTQLHD

Actual result:
--------------
An easily spotted pattern:

]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=27052&edit=1
  Reply With Quote
4 29th December 19:14
php-bugs
External User
 
Posts: 1
Default #27052 : rand() returns easily predictable numbers


ID: 27052
User updated by: webmaster at armondc dot com
Reported By: webmaster at armondc dot com
-Status: Feedback
+Status: Open
Bug Type: Math related
Operating System: Windows 2000 Professional
-PHP Version: 4.3.4
+PHP Version: 4.3.5RC2-dev
New Comment:

I tried it on 4.3.5RC2-dev, and it's still relativly the same. The
pattern is slightly different, but is still as predictable as before.


Previous Comments:
------------------------------------------------------------------------

[2004-01-26 19:04:34] sniper@php.net

Please try using this CVS snapshot:

http://snaps.php.net/php4-STABLE-latest.tar.gz

For Windows:

http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Some rand() related bugs have already been fixed..


------------------------------------------------------------------------

[2004-01-26 15:56:22] webmaster at armondc dot com

On the "actual result" its not as easily spotted without wrapping.
This should give a better picture:

]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\

------------------------------------------------------------------------

[2004-01-26 15:53:26] webmaster at armondc dot com

Description:
------------
I'm not sure if this is a very major problem, or even a bug, but here
goes:

It seems rand() on Windows is very predictable.

I've tried it on 2 Windows Systems, and they were both predictable. It
showed a breif unpredictable segment, then followed by the same string
of characters over and over, and finally a few more unpredictable
characters.

I tried this on a FreeBSD 5.2 System, and it was unpreditable enough.
Seems to be a windows-only problem.

I also noticed bug#11108 - It seems similar, but the submitter was
using his own seeds, and I am using without.

Reproduce code:
---------------
<?php
// This will reproduce the problem
// on windows
for($x = 0; $x < 500; $x++) {
echo chr((rand()%32)+65);
}

// This is a quick-fix, but
// goes agaist the do***entation's
// 'no need for srand()'
for($x = 0; $x < 500; $x++) {
srand(hexdec(substr(md5(microtime()), 0, 8)));
echo chr((rand()%32)+65);
}

?>

Expected result:
----------------
Something a bit random like:

HEOSITFS[ZYH_EVIVVXSLCWRHHC_]_L^PIBTC\TXPBWQLCM^VZSU`UHOG[\VF[KCDGFZM^Q\IG^KAIYPIYBSBIMGHXIBMPHLY\OAZMYAZPJ_`D`F \X\QXR[GP]DQLRHMYIOERBMEKBDJMJPN]J\\KPES^EGRKKO^S[`XL\SSHQXOYQU_JDMM`ZEUEOQOYMHJPYDTRRU_URHYJGXRQYDY ADD]OBVUGC^GGSXPRJJAOAKRAYYN^Q\`XFQJNOWQKAJBFONFXNDZFF IMYRL`ROH^]IM_MINJI\MJJAVG`]_B_EAV`C\O_\DHCHLX_NIO`U^KMJF\`K]VZDOZ_FAWCZC_IQK^[NTPZCC]XEFZ[`\AG[PV^XLPRYVAS]ZPH`^WAXYAZYGK_M_QK`F]PRMP^BBPTRV^KV_VDOLFIM]WQNHVF^DYWGGSGLJ_ZMODG[Z_AAXBYD^FS\MITLZESC`DXLH]NWNIVWZZMVMSXFQMG[O[W[YSPVMTQLHD

Actual result:
--------------
An easily spotted pattern:

]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=27052&edit=1
  Reply With Quote
5 29th December 19:14
External User
 
Posts: 1
Default #27052 : rand() returns easily predictable numbers


ID: 27052
Updated by: sniper@php.net
Reported By: webmaster at armondc dot com
-Status: Open
+Status: Bogus
Bug Type: Math related
Operating System: Windows 2000 Professional
PHP Version: 4.3.5RC2-dev
New Comment:

RTFM:

Note: On some platforms (such as Windows) RAND_MAX is only 32768. If
you require a range larger than 32768, consider using mt_rand()
instead.

Previous Comments:
------------------------------------------------------------------------

[2004-01-26 20:03:17] webmaster at armondc dot com

I tried it on 4.3.5RC2-dev, and it's still relativly the same. The
pattern is slightly different, but is still as predictable as before.

------------------------------------------------------------------------

[2004-01-26 19:04:34] sniper@php.net

Please try using this CVS snapshot:

http://snaps.php.net/php4-STABLE-latest.tar.gz

For Windows:

http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Some rand() related bugs have already been fixed..


------------------------------------------------------------------------

[2004-01-26 15:56:22] webmaster at armondc dot com

On the "actual result" its not as easily spotted without wrapping.
This should give a better picture:

]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\

------------------------------------------------------------------------

[2004-01-26 15:53:26] webmaster at armondc dot com

Description:
------------
I'm not sure if this is a very major problem, or even a bug, but here
goes:

It seems rand() on Windows is very predictable.

I've tried it on 2 Windows Systems, and they were both predictable. It
showed a breif unpredictable segment, then followed by the same string
of characters over and over, and finally a few more unpredictable
characters.

I tried this on a FreeBSD 5.2 System, and it was unpreditable enough.
Seems to be a windows-only problem.

I also noticed bug#11108 - It seems similar, but the submitter was
using his own seeds, and I am using without.

Reproduce code:
---------------
<?php
// This will reproduce the problem
// on windows
for($x = 0; $x < 500; $x++) {
echo chr((rand()%32)+65);
}

// This is a quick-fix, but
// goes agaist the do***entation's
// 'no need for srand()'
for($x = 0; $x < 500; $x++) {
srand(hexdec(substr(md5(microtime()), 0, 8)));
echo chr((rand()%32)+65);
}

?>

Expected result:
----------------
Something a bit random like:

HEOSITFS[ZYH_EVIVVXSLCWRHHC_]_L^PIBTC\TXPBWQLCM^VZSU`UHOG[\VF[KCDGFZM^Q\IG^KAIYPIYBSBIMGHXIBMPHLY\OAZMYAZPJ_`D`F \X\QXR[GP]DQLRHMYIOERBMEKBDJMJPN]J\\KPES^EGRKKO^S[`XL\SSHQXOYQU_JDMM`ZEUEOQOYMHJPYDTRRU_URHYJGXRQYDY ADD]OBVUGC^GGSXPRJJAOAKRAYYN^Q\`XFQJNOWQKAJBFONFXNDZFF IMYRL`ROH^]IM_MINJI\MJJAVG`]_B_EAV`C\O_\DHCHLX_NIO`U^KMJF\`K]VZDOZ_FAWCZC_IQK^[NTPZCC]XEFZ[`\AG[PV^XLPRYVAS]ZPH`^WAXYAZYGK_M_QK`F]PRMP^BBPTRV^KV_VDOLFIM]WQNHVF^DYWGGSGLJ_ZMODG[Z_AAXBYD^FS\MITLZESC`DXLH]NWNIVWZZMVMSXFQMG[O[W[YSPVMTQLHD

Actual result:
--------------
An easily spotted pattern:

]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=27052&edit=1
  Reply With Quote
6 29th December 19:15
php-bugs
External User
 
Posts: 1
Default #27052 : rand() returns easily predictable numbers


ID: 27052
User updated by: webmaster at armondc dot com
Reported By: webmaster at armondc dot com
Status: Bogus
Bug Type: Math related
Operating System: Windows 2000 Professional
PHP Version: 4.3.5RC2-dev
New Comment:

I do not see what RAND_MAX has to do with it, and excuse me if I'm
wrong here-

for($x = 0; $x < 15000; $x++) {
echo chr((rand(0,32768)%32)+65);
}

This code should replicate the problem on a unix-like platform, however
from my tests it doesn't.

Just trying to help


Previous Comments:
------------------------------------------------------------------------

[2004-01-26 20:06:10] sniper@php.net

RTFM:

Note: On some platforms (such as Windows) RAND_MAX is only 32768. If
you require a range larger than 32768, consider using mt_rand()
instead.


------------------------------------------------------------------------

[2004-01-26 20:03:17] webmaster at armondc dot com

I tried it on 4.3.5RC2-dev, and it's still relativly the same. The
pattern is slightly different, but is still as predictable as before.

------------------------------------------------------------------------

[2004-01-26 19:04:34] sniper@php.net

Please try using this CVS snapshot:

http://snaps.php.net/php4-STABLE-latest.tar.gz

For Windows:

http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Some rand() related bugs have already been fixed..


------------------------------------------------------------------------

[2004-01-26 15:56:22] webmaster at armondc dot com

On the "actual result" its not as easily spotted without wrapping.
This should give a better picture:

]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F
[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\

------------------------------------------------------------------------

[2004-01-26 15:53:26] webmaster at armondc dot com

Description:
------------
I'm not sure if this is a very major problem, or even a bug, but here
goes:

It seems rand() on Windows is very predictable.

I've tried it on 2 Windows Systems, and they were both predictable. It
showed a breif unpredictable segment, then followed by the same string
of characters over and over, and finally a few more unpredictable
characters.

I tried this on a FreeBSD 5.2 System, and it was unpreditable enough.
Seems to be a windows-only problem.

I also noticed bug#11108 - It seems similar, but the submitter was
using his own seeds, and I am using without.

Reproduce code:
---------------
<?php
// This will reproduce the problem
// on windows
for($x = 0; $x < 500; $x++) {
echo chr((rand()%32)+65);
}

// This is a quick-fix, but
// goes agaist the do***entation's
// 'no need for srand()'
for($x = 0; $x < 500; $x++) {
srand(hexdec(substr(md5(microtime()), 0, 8)));
echo chr((rand()%32)+65);
}

?>

Expected result:
----------------
Something a bit random like:

HEOSITFS[ZYH_EVIVVXSLCWRHHC_]_L^PIBTC\TXPBWQLCM^VZSU`UHOG[\VF[KCDGFZM^Q\IG^KAIYPIYBSBIMGHXIBMPHLY\OAZMYAZPJ_`D`F \X\QXR[GP]DQLRHMYIOERBMEKBDJMJPN]J\\KPES^EGRKKO^S[`XL\SSHQXOYQU_JDMM`ZEUEOQOYMHJPYDTRRU_URHYJGXRQYDY ADD]OBVUGC^GGSXPRJJAOAKRAYYN^Q\`XFQJNOWQKAJBFONFXNDZFF IMYRL`ROH^]IM_MINJI\MJJAVG`]_B_EAV`C\O_\DHCHLX_NIO`U^KMJF\`K]VZDOZ_FAWCZC_IQK^[NTPZCC]XEFZ[`\AG[PV^XLPRYVAS]ZPH`^WAXYAZYGK_M_QK`F]PRMP^BBPTRV^KV_VDOLFIM]WQNHVF^DYWGGSGLJ_ZMODG[Z_AAXBYD^FS\MITLZESC`DXLH]NWNIVWZZMVMSXFQMG[O[W[YSPVMTQLHD

Actual result:
--------------
An easily spotted pattern:

]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\YRWXENCTQJOP]F[LIBGHU^SDAZ_`MVK\


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=27052&edit=1
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666