[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

foxr foxr at source.lon-capa.org
Thu Oct 6 07:01:55 EDT 2011


foxr		Thu Oct  6 11:01:55 2011 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Add sufficient power to rndseed so that seeds for specific courses can be
  gotten even if the user is not in a course role at the time
  (optional cenv parameter to rndseed).
  
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1132 loncom/lonnet/perl/lonnet.pm:1.1133
--- loncom/lonnet/perl/lonnet.pm:1.1132	Fri Sep 16 22:24:01 2011
+++ loncom/lonnet/perl/lonnet.pm	Thu Oct  6 11:01:55 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1132 2011/09/16 22:24:01 raeburn Exp $
+# $Id: lonnet.pm,v 1.1133 2011/10/06 11:01:55 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2212,7 +2212,7 @@
     my ($name,$id,$debug) = @_;
     $id=&make_key($name,$id);
     if (exists($remembered{$id})) {
-	if ($debug) { &Apache::lonnet::logthis("Earyl return $id of $remembered{$id} "); }
+	if ($debug) { &Apache::lonnet::logthis("Early return $id of $remembered{$id} "); }
 	$accessed{$id}=[&gettimeofday()];
 	$hits++;
 	return ($remembered{$id},1);
@@ -6179,7 +6179,27 @@
     }
    return 'F';
 }
-
+#
+#   Removes the versino from a URI and
+#   splits it in to its filename and path to the filename.
+#   Seems like File::Basename could have done this more clearly.
+#   Parameters:
+#      $uri   - input URI
+#   Returns:
+#     Two element list consisting of 
+#     $pathname  - the URI up to and excluding the trailing /
+#     $filename  - The part of the URI following the last /
+#  NOTE:
+#    Another realization of this is simply:
+#    use File::Basename;
+#    ...
+#    $uri = shift;
+#    $filename = basename($uri);
+#    $path     = dirname($uri);
+#    return ($filename, $path);
+#
+#     The implementation below is probably faster however.
+#
 sub split_uri_for_cond {
     my $uri=&deversion(&declutter(shift));
     my @uriparts=split(/\//,$uri);
@@ -9693,9 +9713,26 @@
     }
     return undef;
 }
-
+#
+#  Determines the random seed for a specific context:
+#
+# parameters:
+#   symb      - in course context the symb for the seed.
+#   course_id - The course id of the form domain_coursenum.
+#   domain    - Domain for the user.
+#   course    - Course for the user.
+#   cenv      - environment of the course.
+#
+# NOTE:
+#   All parameters are picked out of the environment if missing
+#   or not defined.
+#   If a symb cannot be determined the current time is used instead.
+#
+#  For a given well defined symb, courside, domain, username,
+#  and course environment, the seed is reproducible.
+#
 sub rndseed {
-    my ($symb,$courseid,$domain,$username)=@_;
+    my ($symb,$courseid,$domain,$username, $cenv)=@_;
     my ($wsymb,$wcourseid,$wdomain,$wusername)=&whichuser();
     if (!defined($symb)) {
 	unless ($symb=$wsymb) { return time; }
@@ -9703,9 +9740,16 @@
     if (!$courseid) { $courseid=$wcourseid; }
     if (!$domain) { $domain=$wdomain; }
     if (!$username) { $username=$wusername }
-    my $which=&get_rand_alg();
+
+    my $which;
+    if (defined($cenv->{'rndseed'})) {
+	$which = $cenv->{'rndseed'};
+    } else {
+	$which =&get_rand_alg($courseid);
+    }
 
     if (defined(&getCODE())) {
+
 	if ($which eq '64bit5') {
 	    return &rndseed_CODE_64bit5($symb,$courseid,$domain,$username);
 	} elsif ($which eq '64bit4') {




More information about the LON-CAPA-cvs mailing list