[LON-CAPA-users] List::Util

Gerd Kortemeyer korte at lite.msu.edu
Fri Nov 23 10:02:10 EST 2012


Hi,

For anything random, it is best to use the LON-CAPA internal functions, so the randomization is reliably tied to the student, the course, and the instance of the problem. Otherwise, display and grading get messed up. Don't use rand() for anything that's graded.

For shuffling, use the LON-CAPA-internal function &random_permutation(). See the blue question mark documentation on "Script Functions" for all randomization and shuffling functionality.

- Gerd.

On Nov 23, 2012, at 9:53 AM, Seema Ali <sali at vsb.bc.ca> wrote:

> Sorry that was a dumb question.  I'm not that much of a Perl programmer.
> 
> When I need a shuffle function I use a modified version of:
> sub fisher_yates_shuffle {
>        my $deck = shift;  # $deck is a reference to an array
>        my $i = @$deck;
>        while ($i--) {
>            my $j = int rand ($i+1);
>            @$deck[$i,$j] = @$deck[$j,$i];
>        }
>    }
> 
>    # shuffle my mpeg collection
>    #
>    my @mpeg = <audio/*/*.mp3>;
>    fisher_yates_shuffle( \@mpeg );    # randomize @mpeg in place
>    print @mpeg;  
> 
> from: http://perl.active-venture.com/pod/perlfaq4-dataarrays.html
> 
> 
> 
> 
> for first, you might try something like:
>    @blues = qw/azure cerulean teal turquoise lapis-lazuli/;
>    %is_blue = ();
>    for (@blues) { $is_blue{$_} = 1 }  
> 
> I've never used first before so I'm not sure if that'll help or not.  The code is found on the same page.
> 
> I hope that helps.
> 
> From Seema.
> ________________________________________
> From: lon-capa-users-bounces at mail.lon-capa.org [lon-capa-users-bounces at mail.lon-capa.org] on behalf of Gerd Kortemeyer [korte at lite.msu.edu]
> Sent: 23 November 2012 05:20
> To: Discussion list for LON-CAPA users
> Subject: Re: [LON-CAPA-users] List::Util
> 
> Hi,
> 
> On Nov 23, 2012, at 7:56 AM, Peter Dencker <dencker at math.uni-luebeck.de> wrote:
> 
>> 
>> Hi, can one use the functions defined in List::Util ?
>> 
>> I tried
>> 
>> <problem>
>> <script type="loncapa/perl">
>> 
>> use List::Util qw(first shuffle);
>> 
>> </script>
>> </problem>
>> 
>> and this crashed.
> 
> "Use" in general is not supported in scripting environment, since many libraries involve and allow I/O.
> 
> - Gerd.
> _______________________________________________
> LON-CAPA-users mailing list
> LON-CAPA-users at mail.lon-capa.org
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
> _______________________________________________
> LON-CAPA-users mailing list
> LON-CAPA-users at mail.lon-capa.org
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users



More information about the LON-CAPA-users mailing list