Template talk:Random number

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
WikiProject iconNumbers
WikiProject iconThis template is within the scope of WikiProject Numbers, a collaborative effort to improve the coverage of Numbers on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.

Caching has killed this template[edit]

It appears as though the result of ((#time:U)) is caching on the page, meaning that this entire template is broken. I see this as a recent phenomenon, maybe even something that occurred 8 days ago. Each page reload produces no change in the numbers, unless ?action=purge is added to the end. What gives? Surely this whole template is worthless if it doesn't give a different number on each page load. To demonstrate the problem, I'll add a simple {{#time:U}} statement below, and you can reload the page to see it … do nothing:

1716357232

Of course, if you edit this page, it will look like things are okay, because the numbers will change. But only for that single page load. Load the page again, and the number remains fixed at the new value. (Effectively, then, this number is not the current time, but the last time that someone edited this page.) If anyone knows anything about what's going on, please help! CzechOut | 19:35, 21 October 2013 (UTC)[reply]

Caching has always been present. Just reloading the page with the browser without forcing the server to regenerate the page has always been needed. The only difference now is that the ching period is longer, and cache sizes are larger, so the server does not have to refresh the page so often as it is still in the cache.
So time:U has always been the timestamp on the server when the page was saved (cancelling the cache) or regenerated with action=purge, or with a null-edit (save without changes)....
Nothing is broken, it works s expected (with the cache limiting the frequency at which a new value will be taken). verdy_p (talk) 00:10, 22 October 2013 (UTC)[reply]
There's new sandboxed version which avoids the caveats (contins the new code to copy, and the bottom is the test of the sandbox (just copied from the doc page using a different template name to use the sandbox version).
Template:Random number/sandbox
verdy_p (talk) 02:17, 22 October 2013 (UTC)[reply]

Module:Random[edit]

I've put a version in the sandbox that uses Module:Random to generate the randomness. This gets rid of the cyclical problems, and dispenses with the need to specify seeds and primes. If anyone is wondering, the default seed is (number of edits) + (number of pages) + (current Unix time) + floor((milliseconds taken to execute the start of the Lua script) * 1000000000). I think that should be random enough to satisfy most people. :) Check out the module test cases if you want to see it in action. If there are no objections, I'll update the template with the sandbox version in a few days' time. — Mr. Stradivarius ♪ talk ♪ 03:31, 28 November 2013 (UTC)[reply]

Actually, hold that thought. I've just found that Template:Random portal component expects the value returned by this template to be the same for any values on the page, so I'll need to make a new function in the Lua module to accommodate that and check all the transclusions of this template to see which ones need the same number. — Mr. Stradivarius ♪ talk ♪ 05:36, 28 November 2013 (UTC)[reply]
Mr. Stradivarius, is there any reason this hasn't been implemented yet since the |same= parameter was added? BrandonXLF (talk) 00:01, 15 March 2020 (UTC)[reply]
I don't think so. I can't guarantee that nothing would break if you made the switch, though. It would be good to be able to deprecate the |seed= and |prime= parameters, so I would support the change. Best — Mr. Stradivarius ♪ talk ♪ 06:57, 15 March 2020 (UTC)[reply]

No new random number when refreshing the page[edit]

Why does a refresh of the page not display new random numbers...

We need to purge the page to get a new result (action=purge).--Megajoule (talk) 10:02, 2 May 2021 (UTC)[reply]

@Megajoule: This is for performance reasons. The Wikimedia servers use various levels of caching to cope with the millions of requests sent to them from devices asking to view Wikipedia pages. If they had to rebuild a page with a new random number every time, the load would be greatly increased. -- John of Reading (talk) 07:43, 3 May 2021 (UTC)[reply]

Move discussion in progress[edit]

There is a move discussion in progress on Template talk:Random item which affects this page. Please participate on that page and not in this talk page section. Thank you. —RMCD bot 08:21, 2 March 2022 (UTC)[reply]