Difference between revisions of "Issue:Randomseed"

From FollowTheScore
Jump to: navigation, search
(Potential problem)
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Issue
 
{{Issue
 
  |Type        = Change Request
 
  |Type        = Change Request
  |Extension  =  
+
  |Extension  = DPL
  |Version    = next
+
  |Version    = 1.5.3
 
  |Description = Add <tt>randomseed=</tt>''number''
 
  |Description = Add <tt>randomseed=</tt>''number''
  |Status      = open
+
  |Status      = resolved
 
}}
 
}}
  
Line 15: Line 15:
 
   category=Foo|
 
   category=Foo|
 
   randomseed={{#time:Ymd}}|
 
   randomseed={{#time:Ymd}}|
   randomcount=5|
+
   randomcount=5
 +
}}
 
</nowiki></pre>
 
</nowiki></pre>
  
Line 21: Line 22:
  
 
== Reply ==
 
== Reply ==
 +
Completely agree. Is now part of 1.5.3
 +
:[[User:Gero|Gero]] 22:35, 15 November 2007 (CET)
 +
 +
 +
== Problem ==
 +
 +
It doesn't work. I get this message:
 +
<pre><nowiki>
 +
%DPL-1.6.9-Warning: Wrong 'randomseed' parameter: '{{#time:Ymd}}'! Using default: . Help: randomseed= | /^\d*$/.
 +
</nowiki></pre>
 +
How can I get a daily random article?
 +
--[[User:Mr.X|Mr.X]] 17:23, 19 August 2008 (CEST)
 +
 +
== Answer ==
 +
If you are using MW 1.11 or later you must use the latest DPL version. Otherwise you will havce effects like this ( and many others ..) [[User:Gero|Gero]] 17:59, 19 August 2008 (CEST)
 +
 +
 +
:I have MW 1.11.0 and DPL2 1.6.9, I think it's the latest version.
 +
:From DPL2 Manual:
 +
:<pre><nowiki>Magic words like {{PAGENAME}} or {{CURRENTDAY}} cannot be used.</nowiki></pre>
 +
:I think this is the problem. --[[User:Mr.X|Frank (Mr.X)]] 20:36, 19 August 2008 (CEST)
 +
 +
== Solved ==
 +
I had to install [http://www.mediawiki.org/wiki/Extension:LO_Parser_Functions LO Parser Funktions]. Now it works. :-) --[[User:Mr.X|Frank (Mr.X)]] 22:12, 19 August 2008 (CEST)
 +
 +
== Potential problem ==
 +
It seems like manipulating the random seed shouldn't be done, or at last is very bad programming style. Sorry for that, its my code and it souldn't be done that way. A better solution is to transform the string into a random number more directly. In an other extension (RandomInclude) I did it like so (Note this isn't optimum, I just needed a quick fix)
 +
 +
  // Local digest, can be reimplemented
 +
  // MD5 is quite heavy, and can probably be replaced by a simpler digest
 +
  function wfRenderRandomDigest( $any ) {
 +
        $acc = 0;
 +
        if (is_int($any)) $any = dechex($any + 0);
 +
        foreach (str_split(md5("" . $any), 4) as $h) {
 +
                $acc ^= hexdec($h);
 +
        }
 +
        return $acc;
 +
  }
 +
 +
A more general solution for DPL should probably try to estimate how long the generated result will be valid, that is, if the random number changes on a daily basis then the cache time should be set accordingly. Generated lists used on a page should then change the page cache time accordingly. [[User:Jeblad|Jeblad]] 00:11, 28 August 2008 (UTC)

Latest revision as of 01:12, 28 August 2008

Description: Add randomseed=number
Extension / Version: DPL   /   1.5.3
Type / Status: Change Request   /   resolved

Problem

When using the DPL-extension to build semirandom sets of articles, like a main page with changing articles, the set of randomly choosen articles should be kept static for a spesific time period. An easy fix for this is to add a random seed that changes i a predictable way, like once a week or once a day.

Using randomseed will be something like

{{#dpl:
  category=Foo|
  randomseed={{#time:Ymd}}|
  randomcount=5
}}

See also 11891 Add randomseed for a patch. Jeblad 03:41, 14 November 2007 (CET)

Reply

Completely agree. Is now part of 1.5.3

Gero 22:35, 15 November 2007 (CET)


Problem

It doesn't work. I get this message:

%DPL-1.6.9-Warning: Wrong 'randomseed' parameter: '{{#time:Ymd}}'! Using default: . Help: randomseed= | /^\d*$/.

How can I get a daily random article? --Mr.X 17:23, 19 August 2008 (CEST)

Answer

If you are using MW 1.11 or later you must use the latest DPL version. Otherwise you will havce effects like this ( and many others ..) Gero 17:59, 19 August 2008 (CEST)


I have MW 1.11.0 and DPL2 1.6.9, I think it's the latest version.
From DPL2 Manual:
Magic words like {{PAGENAME}} or {{CURRENTDAY}} cannot be used.
I think this is the problem. --Frank (Mr.X) 20:36, 19 August 2008 (CEST)

Solved

I had to install LO Parser Funktions. Now it works. :-) --Frank (Mr.X) 22:12, 19 August 2008 (CEST)

Potential problem

It seems like manipulating the random seed shouldn't be done, or at last is very bad programming style. Sorry for that, its my code and it souldn't be done that way. A better solution is to transform the string into a random number more directly. In an other extension (RandomInclude) I did it like so (Note this isn't optimum, I just needed a quick fix)

 // Local digest, can be reimplemented
 // MD5 is quite heavy, and can probably be replaced by a simpler digest
 function wfRenderRandomDigest( $any ) {
       $acc = 0;
       if (is_int($any)) $any = dechex($any + 0);
       foreach (str_split(md5("" . $any), 4) as $h) {
               $acc ^= hexdec($h);
       }
       return $acc;
 }

A more general solution for DPL should probably try to estimate how long the generated result will be valid, that is, if the random number changes on a daily basis then the cache time should be set accordingly. Generated lists used on a page should then change the page cache time accordingly. Jeblad 00:11, 28 August 2008 (UTC)