Jump to content

Module talk:Random

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Isaacl (talk | contribs) at 07:42, 2 December 2013 (Setting random seed: is the logic reversed?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Setting random seed

I suggest setting a flag when the random seed is set, so it can be set just once. I know it won't help with multiple invocations of the module, since the flag won't be preserved, but at least when random numbers are being generated multiple times during a given function call, the risk of repeating the same seed value will be eliminated. isaacl (talk) 17:39, 30 November 2013 (UTC)[reply]

Actually, sometimes generating the same number is necessary, as some wikicode assumes that {{rand}} generates the same number every time it is called on the same page. (This can now be done with the |same= parameter.) But I think you do have a point - it was messy code to call setRandomSeed so many times. I've reworked the module so that it is only called once. — Mr. Stradivarius ♪ talk ♪ 07:26, 2 December 2013 (UTC)[reply]
Just out of curiosity, could you point me to one of the examples where it is expected that {{rand}} will produce the same number? Having a common entry point function for each of the generated wrapper function is a nice way to set the seed once. However, regarding the logic: is the logic reversed for the low traffic check? In the case where using the same seed is desired and the site is not low traffic, then stats.edit may change rapidly, so you should instead use os.time() rounded to the seed refresh rate? isaacl (talk) 07:42, 2 December 2013 (UTC)[reply]