How is the colour of the avatar in PF is decided?

  • Thread starter MathematicalPhysicist
  • Start date
In summary: } return $innerClassHtml; }The getDefaultAvatarHtml() function gets the avatar HTML for a user.If the user does not have an avatar, then the function sets the style to be empty.If the user has an avatar, then the function looks for a style attribute in the outer attributes.If the style attribute is not empty, then the function sets the style to that attribute.Otherwise, the function returns the inner class HTML for the avatar.
  • #1
MathematicalPhysicist
Gold Member
4,699
371
the question in the title.
 
Physics news on Phys.org
  • #2
As far as I know it's random. Obviously the background and letter colors are coordinated to keep contrast.
 
  • Like
Likes jedishrfu
  • #4
Greg Bernhardt said:
As far as I know it's random. Obviously the background and letter colors are coordinated to keep contrast.
Nothing which is in a classical computer is truly random.
Though you can say that you don't know how is the colour chosen.
 
  • Skeptical
Likes DrClaude
  • #5
MathematicalPhysicist said:
Nothing which is in a classical computer is truly random.
Though you can say that you don't know how is the colour chosen.
That's like saying that coin flips aren't really random because you could use Newton's laws to calculate on which side the coin will end up. Some results from computers can be random FAPP.
 
  • #6
DrClaude said:
That's like saying that coin flips aren't really random because you could use Newton's laws to calculate on which side the coin will end up. Some results from computers can be random FAPP.
And what's wrong with that?
If you know what the outcome will be how it can be random?
We don't actually know how to calculate this because of the unknown unknowns.
 
  • #7
MathematicalPhysicist said:
And what's wrong with that?
If you know what the outcome will be how it can be random?
We don't actually know how to calculate this because of the unknown unknowns.
In @DrClaude's response, 'FAPP' abbreviates 'for all practical purposes'.
 
  • Like
Likes MathematicalPhysicist and DrClaude
  • #8
MathematicalPhysicist said:
If you know what the outcome will be how it can be random?
The point is that you can't know what the outcome will be. One could in theory dive in the code and try to figure out what the next color for an avatar will be, but even then that will probably depend on exactly how many new accounts have been created since the state of the program was checked. So FAPP no one knows, not even @Greg Bernhardt, what a particular new user's avatar's color will be. Therefore, it is random.
 
  • #9
sysprog said:
In @DrClaude's response, 'FAPP' abbreviates 'for all practical purposes'.
I searched google for FAPP and got a colorful definition from the urban dictionary which won't be displayed here. So I was quite sure that wasn't what he meant... :-D
 
Last edited by a moderator:
  • #10
MathematicalPhysicist said:
So I was quite sure that wasn't what he meant... :-D
If you knew that @DrClaude didn't mean that, and you didn't confidently surmise what he did mean, you could have asked, and if you did know what he meant, there wasn't much good reason for you to take him to task over the distinction between web server random number generators that produce imperfectly random numbers that are nonetheless usably random, and numbers that are more completely random.
 
  • #11
MathematicalPhysicist said:
Nothing which is in a classical computer is truly random.
So you're looking for a quantum explanation for how the dynamic avatars are built? :oldconfused:

Let me take a look and see if I can find the code for it.
 
  • Like
Likes Wrichik Basu
  • #12
Greg Bernhardt said:
So you're looking for a quantum explanation for how the dynamic avatars are built? :oldconfused:

Let me take a look and see if I can find the code for it.
I'm not a xenforo licensee, so I don't have access to the source code; however, if you're right about the color being 'random', presumably over a predefined pallette (the color and other characteristics can be overridden in css in file message.less, according to content of the discussion thread a link to which was posted by @jedishrfu), you would have to look at the server's php.ini file to ensure that php is getting its numbers from /dev/random, and then investigate the specifics of the implementation there, in order to get a reasonable idea of 'how random' the numbers generated really are, and the 'quantum explanation' would extend only to the ensourcement of the numbers in the /dev/random entropy pool.
 
  • Like
Likes Wrichik Basu and jedishrfu
  • #13
sysprog said:
you would have to look at the server's php.ini file to ensure that php is getting its numbers from /dev/random, and then investigate the specifics of the implementation there, in order to get a reasonable idea of 'how random' the numbers generated really are, and the 'quantum explanation' would extend only to the ensourcement of the numbers in the /dev/random entropy pool.
Honestly I don't have time for all this. Best I can do is find the php code. 😉
 
  • Like
Likes Wrichik Basu
  • #14
Greg Bernhardt said:
Honestly I don't have time for all this. Best I can do is find the php code. 😉
That's in itself far beyond any reasonable call of duty. :oldwink:
 
  • #15
Here is the php code (at least most of it)

PHP:
protected function getDefaultAvatarHtml($username, $innerClassHtml, array &$outerAttributes)
    {
        $styling = $this->getDefaultAvatarStyling($username);

        if (empty($outerAttributes['style']))
        {
            $outerAttributes['style'] = '';
        }
        else
        {
            $outerAttributes['style'] .= '; ';
        }
        $outerAttributes['style'] .= "background-color: $styling[bgColor]; color: $styling[color]";

        if (empty($outerAttributes['class']))
        {
            $outerAttributes['class'] = '';
        }
        else
        {
            $outerAttributes['class'] .= ' ';
        }
        $outerAttributes['class'] .= 'avatar--default avatar--default--dynamic';

        return '<span class="' . $innerClassHtml . '">' . $styling['innerContent'] . '</span>';
    }

    protected function getDefaultAvatarStyling($username)
    {
        if (!isset($this->avatarDefaultStylingCache[$username]))
        {
            $bytes = md5($username, true);
            $r = dechex(round(5 * ord($bytes[0]) / 255) * 0x33);
            $g = dechex(round(5 * ord($bytes[1]) / 255) * 0x33);
            $b = dechex(round(5 * ord($bytes[2]) / 255) * 0x33);
            $hexBgColor = sprintf('%02s%02s%02s', $r, $g, $b);

            $hslBgColor = \XF\Util\Color::hexToHsl($hexBgColor);

            $bgChanged = false;
            if ($hslBgColor[1] > 60)
            {
                $hslBgColor[1] = 60;
                $bgChanged = true;
            }
            else if ($hslBgColor[1] < 15)
            {
                $hslBgColor[1] = 15;
                $bgChanged = true;
            }

            if ($hslBgColor[2] > 85)
            {
                $hslBgColor[2] = 85;
                $bgChanged = true;
            }
            else if ($hslBgColor[2] < 15)
            {
                $hslBgColor[2] = 15;
                $bgChanged = true;
            }

            if ($bgChanged)
            {
                $hexBgColor = \XF\Util\Color::hslToHex($hslBgColor);
            }

            $hslColor = \XF\Util\Color::darkenOrLightenHsl($hslBgColor, 35);
            $hexColor = \XF\Util\Color::hslToHex($hslColor);

            $bgColor = '#' . $hexBgColor;
            $color = '#' . $hexColor;

            if (preg_match($this->avatarLetterRegex, $username, $match))
            {
                $innerContent = htmlspecialchars(utf8_strtoupper($match[0]));
            }
            else
            {
                $innerContent = '?';
            }

            $this->avatarDefaultStylingCache[$username] = [
                'bgColor'      => $bgColor,
                'color'        => $color,
                'innerContent' => $innerContent
            ];
        }

        return $this->avatarDefaultStylingCache[$username];
    }
 
  • Haha
  • Like
Likes mfb and sysprog
  • #16
@MathematicalPhysicist let's not get hung up here on the notion of random.

Basically when we don't know how something is done it may appear random. However, further testing may reveal a pattern and eventually we learn something new. In the case of these default avatars it appears that they select the color scheme from a table so as to not place two similar colors for text and background.

I did a brief check via our "at"+username feature to see if I could see a pattern and I could not.

At first, I thought it might be:
- based on the first letter - no
- based on the first n letters - no

Leaving these two choices:
- based on a hash of the name
- based on random selection

These choices could be tested by starting with a default avatar noting its color scheme and then changing to a new avatar and then changing back. If you get the same avatar then its likely not random but based on some has of the name and/or or data in your description.

It is true that computer software cannot generate truly random without some hardware assist. However for all practical purposes the random number generators in computer software today are pretty good approximations for random numbers. In general, the random seed that initializes the generator code comes from the clock microseconds. You can however for code testing select a known seed and generate a repeatable list of "random" numbers.

https://en.wikipedia.org/wiki/Random_seed

These algorithms go through a lot of extensive testing as user generated algorithms tend to have a bias that comes out in the statistics taken of the sequence. Years ago, a math programmer at GE discovered for one such sequence that if you took the numbers generated as triplets and plotted them in 3D space they would all appear on a tilted plane indicating that given the first few numbers you could predict the next number. You would probably never notice a pattern like this but an implicit bias would occur in your results due to the generation of poorly constructed pseudo-random numbers.

You can learn more here at Khan Academy:

https://www.khanacademy.org/computi...pt/v/random-vs-pseudorandom-number-generators

Lastly, UUIDs utilize a form of pseudo-random generation based on the system clock to ensure that all numbers generated across all computers are unique for all practical purposes:

https://en.wikipedia.org/wiki/Universally_unique_identifier

https://towardsdatascience.com/are-uuids-really-unique-57eb80fc2a87

I can't wait for that hapless programmer who has to debug a duplicate occurrence of UUID causing a problem in his/her code. Chances are though it will be chalked up to a hiccup somewhere and glossed over since its unlikely to be reproducible.
 
  • Like
Likes sysprog
  • #17
So the color is genned from the MD5 hash on the username, which is as unpredictable as the (unique) usernames are, and then filtered through some integers to keep the colors inside a determined set of ranges. That's close enough to random for purposes of the original inquiry in this thread. Thanks, @Greg Bernhardt, for finding and posting the code.
 
  • Like
Likes jedishrfu and Greg Bernhardt
  • #18
Thanks @Greg Bernhardt the answer is in the code they do an md5 hash of the username and pick out indexes for the colors in some color table.
exerpted from Greg's PHP code post:
            $bytes = md5($username, true);
            $r = dechex(round(5 * ord($bytes[0]) / 255) * 0x33);
            $g = dechex(round(5 * ord($bytes[1]) / 255) * 0x33);
            $b = dechex(round(5 * ord($bytes[2]) / 255) * 0x33);
            $hexBgColor = sprintf('%02s%02s%02s', $r, $g, $b);
 
Last edited:
  • #19
Please don't tell me after a while that Greg's servers use Quantum computation to choose an avatar. :olduhh:
 
  • #20
jedishrfu said:
Thanks @Greg
You just tagged the wrong person.
 
  • #21
Oops! It was a pseudo-random mistake, I swear.
 
  • Haha
  • Like
Likes DrClaude and Wrichik Basu
  • #22
jedishrfu said:
Oops! It was a pseudo-random mistake, I swear.
That means it will eventually happen again. :oldeek:
 
  • #23
Greg Bernhardt said:
So you're looking for a quantum explanation for how the dynamic avatars are built? :oldconfused:

Let me take a look and see if I can find the code for it.
Dunno, I once learned electronic devices and also still learn solid state physics.

The transistors that make our computers (the classical computers not the quantum computers), are based on Quantum Physics (that makes me wonder how different can a quantum computer be from classical computer if they are built on the same transistors, that's for another thread), but their outcomes are still a sequence of 0-1 which are determined classically there are no qubits there.

I genuinely thought there was a way to determine the colour.
I am asking since the same colour here in my avatar also appeared in the math.stackexchange, so I guess that's sort of a coincidence.
 
  • #24
Probably not a coincidence as they may be using the same software as PF with different outward color schemes...

Often coincidences harbor hidden connections that weren't obvious at first sight. There was a story of an autographed children's book lost in the US appearing years later in a book reseller in France found by the now grown child who owned it. At first, it seemed to be a remarkable coincidence until you discover that the French nanny was a common link.
 
  • #25
MathematicalPhysicist said:
I am asking since the same colour here in my avatar also appeared in the math.stackexchange, so I guess that's sort of a coincidence.
You are using a custom image as an avatar though.
 
  • #27
jedishrfu said:
Probably not a coincidence as they may be using the same software as PF with different outward color schemes...
StackExchange sites don't use XF. They have their own software, much different from PF.
 
  • Like
Likes jedishrfu
  • #28
Greg Bernhardt said:
You are using a custom image as an avatar though.
I meant before I uploaded the custom pic, the same colour used in both websites.
 
  • #29
Here is back the colour.
 
  • #30
Could be using a common php library then?
 
  • Like
Likes sysprog and Wrichik Basu
  • #31
MathematicalPhysicist said:
I meant before I uploaded the custom pic, the same colour used in both websites.
You could test your observation for probable non-coincidentiality by having a friend register with the same new username at both sites, and seeing whether the friend's 2 color pairs (letter and background) are also the same -- establishing repeatability is important in scientific investigation ...
 
  • Like
Likes jedishrfu
  • #32
jedishrfu said:
Could be using a common php library then?
Could be, but generally StackExchange site developers won't publish the code for the public. In fact, getting hold of site developers is much more difficult there than in PF, because a simple ping to Greg won't work there.

One option is that @MathematicalPhysicist can post a thread at the Maths Meta SE and see if you can get the php code. I have almost left SE, visited last 6 months back. So there are less chances anyone will actually listen to me in the Physics Meta SE.
 
  • #34
I'm doing something wrong, php uses a different md5 or something else went wrong. Tried to verify this with Woolyabyss (randomly picked user). Username md5 starts with a7791b which leads to 3,2,1 in the calculation but #996633 is a brown, not a green.

Edit: Okay, it is the md5. This calculator produces 29e06d or 1,5,2, and #33FF66 is green.
 
  • Like
Likes Wrichik Basu and sysprog

1. How is the color of the avatar in PF decided?

The color of the avatar in PF is decided based on a combination of factors, including the user's preferences, the design of the platform, and the coding of the website.

2. Is the color of the avatar in PF chosen randomly?

No, the color of the avatar in PF is not chosen randomly. While there may be an element of randomness in some cases, the color is usually determined by specific criteria set by the platform or the user.

3. Can I change the color of my avatar in PF?

Yes, in most cases, users are able to change the color of their avatar in PF. This can usually be done through the platform's settings or preferences menu.

4. Are there any scientific reasons for the color choices in PF avatars?

There may be scientific reasons for the color choices in PF avatars, depending on the platform and its goals. For example, certain colors may be associated with certain emotions or may be chosen to improve user experience.

5. How does the color of my avatar in PF affect my experience on the platform?

The color of your avatar in PF may affect your experience on the platform in various ways. For example, it may influence how other users perceive you, or it may impact your own mood and behavior while using the platform.

Similar threads

Replies
17
Views
1K
  • Feedback and Announcements
Replies
9
Views
843
  • Feedback and Announcements
Replies
5
Views
653
  • Feedback and Announcements
Replies
7
Views
1K
  • Feedback and Announcements
Replies
1
Views
1K
  • Feedback and Announcements
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
782
  • Feedback and Announcements
Replies
3
Views
778
  • Feedback and Announcements
Replies
6
Views
1K
Back
Top