#51739 closed defect (bug) (wontfix)
Randomize Header Images aren't actually random
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
Using WP 5.5.3, with Twenty Eleven theme. I have uploaded 24 header images and selected Customize -> Header -> Randomizing Uploaded Headers.
The problem: the site displays some of those images, but definitely does not give a uniform distribution. Certain images (not always the same ones) appear three or four times as frequently as others.
I decided to check the behavior of 100 refreshes of the page at https://randomneuronsfiring.com. Here are the results:
8 bent branch
7 house with christmas lights
6 trail to franklin hill
6 tennis court fence
6 second mirrored sunset
6 mirrored sunset
6 Holts ledge (little field in center)
5 sunset with big pine in center
5 sunset on snowy field
5 moon mirrored on lake
5 lone red tree
4 ice flowers
4 holts ledge horizon
4 christmas trees on common
5 sun shining on frozen pond
3 orange sky
3 hoarfrost
2 lake beach
2 house from hill
2 foggy top to post hill
2 compass hill view
1 pond from pinnacle
1 forest glade
1 foliage on papoose trail
My observations/questions:
- The expected result, of course, is that all images appear roughly the same number of times: for 100 samples of the 24 images is about four occurrences of each. The distribution above doesn't meet that expectation.
- I observed that the same image frequently appears twice in a row. This is undesirable, because the viewer doesn't realize that they will (often/usually) be different.
- The images seem to "get stuck" in small cycles, showing a small set of images a couple times in a row before moving on to "other sets" of images.
- This is hardly a crippling behavior. But it's annoying, and I work on the principle, "We promise not to fix it if we don't know it's broke." :-)
Thanks for listening
Change History (8)
This ticket was mentioned in Slack in #forums by otto42. View the logs.
4 years ago
#3
@
4 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
100 samples is far too small, and the random functions used in this case are not "true" randomness to begin with, but only pseudo-random functions.
Even so, random does not guarantee uniform distribution, as that would not be random. That would be "shuffle", at best.
Don't think there is anything to be fixed here, as true randomness would be somewhat overkill and slow for the desired use case. True randomness in computing systems tends to be limited to cryptographic uses.
#4
@
4 years ago
Thank you all for your extremely kind responses. As I said in my [note on the forum,](https://wordpress.org/support/topic/randomize-header-images-not-random/#post-13641522) I have done some modeling of my own, running a Python program several times, to look at the distribution of random.choices() from a set of 24 items. You’re correct: the distribution I presented doesn’t seem to be out of line for actual random selection.
Nonetheless, my concern is one of user experience: Images don’t appear random to the viewer. As I noted:
- The same images frequently appear two times in a row.
- A few images frequently appear several times “in a cluster”. This doesn’t "seem" to be random (even if it is, numerically).
I'm willing to leave this ticket closed for now, but have these follow-up requests:
1) Where is the code (what source file) that performs the randomizing?
2) Does the randomizing code have any notion of the "last image shown"? (I am thinking of letting the next image be "n+random(0,5) modulo number of images" so the next image "walks progressively through all images."
Thank you again.
#5
@
4 years ago
If you're using the standard methods, then it eventually selects the header image using PHP's array_rand function. See https://www.php.net/manual/en/function.array-rand.php for more info.
Now, that function uses a pseudo random number generator which is not actually random, but let's assume it was, for funzies.
You have 24 images. What are the odds that you get the same one twice in a row? You might be surprised to learn that the answer is 1 in 24. Therefore, in a tiny sample test of 100, that should happen a bit more than 4 times.
Why is it one in 24? Well, if we assume that each random choice is independent, then you pick one out of 24, and then you pick again, out of the same set of 24. The first choice actually doesn't matter, we're only concerned that the second one is the same as the first. And it has a 1 in 24 chance to be the same, if the randomization is true and fair.
People don't understand what "random" really means. It doesn't mean average, it doesn't mean equal, and it certainly doesn't mean that you don't get the same thing twice. You often get a result a lot more than you think you will, if you just think about it for a bit.
#6
follow-up:
↓ 7
@
4 years ago
Thanks again for this response. I was wrong - this is not a bug. Instead, I'm asking for advice. (You have convinced me - and my own experiments support it - that I'm looking at results of a random sequence.)
A better heading for this ticket might be that the header image sequence is too random. It's a problem of the sample set. You point out that 100 samples is small.
But for "normal viewers" who only read a few pages at a time, the set is very, very small. Consequently it doesn't feel random. They don't realize that the images change, since the same images seem to repeat frequently.
So in a personal quest for an algorithm that might allow the image changes to feel random, I rephrase my requests:
- Would you tell me which WordPress source file performs the header image randomizing function?
- Do you know if the randomizing code has any notion of the "last image shown"? (I would like to experiment with letting the next image be "current image+random(1,5) modulo number of images" so the next image "walks progressively through all images.")
Thank you again.
#7
in reply to:
↑ 6
@
4 years ago
Replying to richbhanover:
- Would you tell me which WordPress source file performs the header image randomizing function?
This line, right here:
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/theme.php#L1299
- Do you know if the randomizing code has any notion of the "last image shown"? (I would like to experiment with letting the next image be "current image+random(1,5) modulo number of images" so the next image "walks progressively through all images.")
It does not do this, it is a simple call to array_rand.
I don't see how a random result would meet this expectation. It seems that the expectation is for an equal distribution, which "random" is not.