[Chicago-talk] PERL mortgage

Brad Doty bdoty at eqtc.com
Thu May 20 08:51:56 PDT 2010


OK, what party within the Perl community went and opened a mortgage
broker?

http://www.perlmortgage.com/bankrate/landing/index2.html

  
Thanks,

bRad


-----Original Message-----
From: chicago-talk-request at pm.org
Reply-to: chicago-talk at pm.org
To: chicago-talk at pm.org
Subject: Chicago-talk Digest, Vol 82, Issue 9
Date: Tue, 18 May 2010 12:00:29 -0700

Send Chicago-talk mailing list submissions to
	chicago-talk at pm.org

To subscribe or unsubscribe via the World Wide Web, visit
	http://mail.pm.org/mailman/listinfo/chicago-talk
or, via email, send a message with subject or body 'help' to
	chicago-talk-request at pm.org

You can reach the person managing the list at
	chicago-talk-owner at pm.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Chicago-talk digest..."


Today's Topics:

   1. Random first numbers (Alan Mead)
   2. Re: Random first numbers (Lee Aylward)
   3. Re: Random first numbers (Dean Serenevy)
   4. Re: Random first numbers (Alan Mead)
   5. Re: Random first numbers (Andy Lester)
   6. Re: Random first numbers (Andrew Moore)


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

Message: 1
Date: Mon, 17 May 2010 16:25:10 -0500
From: Alan Mead <amead2 at alanmead.org>
Subject: [Chicago-talk] Random first numbers
To: "Chicago.pm chatter" <chicago-talk at pm.org>
Message-ID: <4BF1B436.6020409 at alanmead.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

I have a CGI-based study coded in Perl that needs to randomly assign 
participants to conditions.  The code below sucks:

  my @conditions = qw/cond1 cond2 cond3 cond4a/;
  shuffle(@conditions);
  $$state{'condition'} = $conditions[0];

I've just run through a dozen tests and cond3 appeared 90% of the time 
and cond2 10% of the time (cond1 and cond4a never appearing).  I haven't 
run the numbers, but I think this is "statistically significant". I 
think my shuffle is a "good" one from the on-line Perl lore, but maybe 
I'm wrong:

#----------------------------------------------------------
# Durstenfeld's implementation of Fisher and Yates
#----------------------------------------------------------
sub shuffle {
  my $n = scalar @_;
  while ( $n > 0 ) {
    $n--;
    my $j = int rand $n;
    ($_[$j], $_[$n]) = ($_[$n], $_[$j]); # swap
  }
}

Assuming that shuffle() is not the culprit, I think it's just that when 
I run this code quickly/repeatedly, rand() is getting seeded with 
substantially the same value and is generating essentially the same 
initial value.  If so, my question is whether there is a better way to 
generate random numbers (so that the first values are more random). 

I was wondering if anyone agreed/disagreed and whether anyone had a 
"lazy" solution... if not, I can enforce better randomness by keeping 
some sort of state in a database.

-Alan

-- 
Alan D. Mead, Ph.D.
Assistant Professor of Industrial and Organization Psychology
Scientific Advisor to the Center for Research and Service
Illinois Institute of Technology
3101 South Dearborn, 2nd floor
Chicago IL 60616
+312.567.5933 (Campus)
+815.588.3846 (Home Office)
+312.567.3493 (Fax)

http://www.iit.edu/~mead
http://www.center.iit.edu
http://www.alanmead.org

He who fights with monsters should be careful lest he
thereby become a monster.
-- Friedrich Nietzsche, "Beyond Good and Evil"



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

Message: 2
Date: Mon, 17 May 2010 16:49:40 -0500
From: Lee Aylward <lee at laylward.com>
Subject: Re: [Chicago-talk] Random first numbers
To: chicago-talk at pm.org
Message-ID: <20100517164940.15bf78a2 at hactar.servercentral.net>
Content-Type: text/plain; charset=US-ASCII

Hi,

I typically use List::Util's shuffle function. I can't really say if
it will give you better results, though.

-- 
Lee

On Mon, 17 May 2010 16:25:10 -0500
Alan Mead <amead2 at alanmead.org> wrote:

> I have a CGI-based study coded in Perl that needs to randomly assign 
> participants to conditions.  The code below sucks:
> 
>   my @conditions = qw/cond1 cond2 cond3 cond4a/;
>   shuffle(@conditions);
>   $$state{'condition'} = $conditions[0];
> 
> I've just run through a dozen tests and cond3 appeared 90% of the
> time and cond2 10% of the time (cond1 and cond4a never appearing).  I
> haven't run the numbers, but I think this is "statistically
> significant". I think my shuffle is a "good" one from the on-line
> Perl lore, but maybe I'm wrong:
> 
> #----------------------------------------------------------
> # Durstenfeld's implementation of Fisher and Yates
> #----------------------------------------------------------
> sub shuffle {
>   my $n = scalar @_;
>   while ( $n > 0 ) {
>     $n--;
>     my $j = int rand $n;
>     ($_[$j], $_[$n]) = ($_[$n], $_[$j]); # swap
>   }
> }
> 
> Assuming that shuffle() is not the culprit, I think it's just that
> when I run this code quickly/repeatedly, rand() is getting seeded
> with substantially the same value and is generating essentially the
> same initial value.  If so, my question is whether there is a better
> way to generate random numbers (so that the first values are more
> random). 
> 
> I was wondering if anyone agreed/disagreed and whether anyone had a 
> "lazy" solution... if not, I can enforce better randomness by keeping 
> some sort of state in a database.
> 
> -Alan
> 


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

Message: 3
Date: Mon, 17 May 2010 19:19:16 -0400
From: Dean Serenevy <dean at serenevy.net>
Subject: Re: [Chicago-talk] Random first numbers
To: "Chicago.pm chatter" <chicago-talk at pm.org>
Message-ID: <4BF1CEF4.7070601 at serenevy.net>
Content-Type: text/plain; charset=UTF-8


On 05/17/2010 05:25 PM, Alan Mead wrote:
> #----------------------------------------------------------
> # Durstenfeld's implementation of Fisher and Yates
> #----------------------------------------------------------
> sub shuffle {
>  my $n = scalar @_;
>  while ( $n > 0 ) {
>    $n--;
>    my $j = int rand $n;
>    ($_[$j], $_[$n]) = ($_[$n], $_[$j]); # swap
>  }
> }
> 
> Assuming that shuffle() is not the culprit, I think it's just that when

Bad assumption. That is not the Fisher-Yates shuffle. Try this (from perlfaq):

sub shuffle {
  my $n = @_;
  while (--$n) {
    my $j = int rand ($n+1);
    @_[$n,$j] = @_[$j,$n];
  }
}

Note that:
* a no-op is possible in this version ($n may equal $j)
* The last $n through the loop is 1 not 0

Good Day,
  Dean


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

Message: 4
Date: Mon, 17 May 2010 18:29:51 -0500
From: Alan Mead <amead2 at alanmead.org>
Subject: Re: [Chicago-talk] Random first numbers
To: "Chicago.pm chatter" <chicago-talk at pm.org>
Message-ID: <4BF1D16F.9050707 at alanmead.org>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"

Dean Serenevy wrote:
> On 05/17/2010 05:25 PM, Alan Mead wrote:
>   
>> Assuming that shuffle() is not the culprit, I think it's just that when
>>     
>
> Bad assumption. That is not the Fisher-Yates shuffle. Try this (from perlfaq):
>
> sub shuffle {
>   my $n = @_;
>   while (--$n) {
>     my $j = int rand ($n+1);
>     @_[$n,$j] = @_[$j,$n];
>   }
> }
>
>   

Under light testing, this seems much better.  Thanks!

-Alan




More information about the Chicago-talk mailing list