tstarling added a comment.

  We (Brad Jorsch and I) didn't want random numbers in Scribunto because it 
encourages an inefficient implementation of things like "spotlight" templates 
that show a random featured article from a list of such articles. We want to 
cache the output from Scribunto but then people will see the same random 
selection for months at a time, so users will inevitably try to defeat caching 
or incentivize purge requests.
  
  For this application I would suggest passing a random number in $setupOptions 
to LuaEngine::registerInterface(). Implement your own LCG 
<https://en.wikipedia.org/wiki/Linear_congruential_generator> which should be 
doable in 2 lines of code even though you only have floating point numbers. The 
multiplication needs to fit in the 53-bit mantissa of the floating point number 
without rounding, which is not a problem for say MINSTD m=2^31-1, a=48271, 
which gives a maximum base 2 logarithm of 47.
  
  Or just increment a counter and report every time the counter mod N is zero. 
Offset the counter at startup by a random number.
  
  If you actually wanted to unconditionally seed the global RNG, this would not 
be the right way to do it. Better to seed it in mw.executeModule() based on an 
additional parameter passed from PHP.
  
  os.clock() only looks attractive as a random number source because we've 
deliberately avoided providing better random number sources to Lua.

TASK DETAIL
  https://phabricator.wikimedia.org/T360891

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: hoo, tstarling
Cc: tstarling, Lucas_Werkmeister_WMDE, Aklapper, Michael, 
Danny_Benjafield_WMDE, Isabelladantes1983, Themindcoder, Adamm71, S8321414, 
Jersione, Hellket777, LennardHofmann, LisafBia6531, Astuthiodit_1, 786, 
Biggs657, karapayneWMDE, Invadibot, maantietaja, Juan90264, Alter-paule, 
Beast1978, ItamarWMDE, Un1tY, Akuckartz, Hook696, Kent7301, joker88john, 
CucyNoiD, Nandana, Gaboe420, lucamauri, Giuliamocci, Cpaulf30, Lahi, Gq86, 
Af420, Bsandipan, GoranSMilovanovic, QZanden, KimKelting, LawExplorer, 
Lewizho99, Maathavan, _jensen, rosalieper, Neuronton, Scott_WUaS, 
Wikidata-bugs, aude, Mbch331
_______________________________________________
Wikidata-bugs mailing list -- wikidata-bugs@lists.wikimedia.org
To unsubscribe send an email to wikidata-bugs-le...@lists.wikimedia.org

Reply via email to