[Noisebridge-discuss] PHP sucks [was Re: [drama] New logo source?]

Leif Ryge leif at synthesize.us
Tue Jan 12 22:24:32 UTC 2010


Kelly wrote:
> Wow, so that was on the homepage. I've not yet gotten anything but the
> WU logo there.
> 
> As far as a secure way to add logos, maybe we could just have people
> upload and then have a secure person add it?  Would ops be willing to
> take this on?  Seems like it should be some official contactable
> source that's not specific individuals.
> 
> And in the meantime, can we see the code that's running this randomizer?
> 
> -K
> 
> On Mon, Jan 11, 2010 at 3:02 PM, Michael C. Toren <mct at toren.net> wrote:
>> On Mon, Jan 11, 2010 at 01:36:20PM -0800, Jonathan Lassoff wrote:
>>> I didn't want to hammer the server any harder, so it's hard to say if
>>> only 2000 tightly-spaced samples are statistically significant, but I'll
>>> let you draw your own conclusions:
>> I ran a similar experiment on the 9th, using a silly bash+curl+awk
>> one-liner that requested the root document 1000 times, randomly sleeping
>> between 1 and 3 seconds between each request in order to be kind to the
>> server.  The results from that experiment were:
>>
>>  - 508/1000 requests (50.8%):  wunderground-noisebridge.png
>>  - 335/1000 requests (33.5%):  NB-logo-red-black-med.png
>>  - 157/1000 requests (15.7%):  Pissingponynb-131.png
>>
>> It does appear to be heavily weighted.
>>
>> -mct

Ok, this was bothering me, so I just went and checked to see how the
randomizer was implemented. Here it is:

$images =
array("https://www.noisebridge.net/wunderground-noisebridge.png","https://www.noisebridge.net/Pissingponynb-131.png",
"https://www.noisebridge.net/NB-logo-red-black-med.png");
$rand_keys = array_rand($images, 2);
$wgLogo = $images[$rand_keys[0]];

I have no idea why someone chose to ask for 2 random values when they 
only needed one, but you might expect that this would produce suitably 
random results anyway. And, with an older version of PHP, I believe this 
  code actually would yield an even weighting. And, with a newer 
version, it would pick the first item 2/3 of the time and never pick the 
third at all. And, with our middle-aged version of PHP (5.2.4-2), it 
produces the distribution observed above. Hooray for PHP!

Here is a demo from 5.2.6-3ubuntu4.4:
$ php5 -r '$a=array(1,2,3); for ($i=1; $i<10000; $i++) { $r = 
array_rand($a, 2); echo "$r[0] $r[1]\n"; }'|sort|uniq -c
    3398 0 1
    1641 0 2
    1641 1 2
    1666 2 0
    1653 2 1

~leif



More information about the Noisebridge-discuss mailing list