I always thought that XR wasn't important because he had a personality, but because he was designed to "learn and grow." As in, there was something unique in his code that made it very easy for him to rewire his own mind and develop new personality traits. The programmers in their galaxy may well be perfectly capable of designing robots that can artificially act human. (Heck, we've got some ourselves:
alice.pandorabots.com/. They aren't that good, but still...) The majority of the robots we see may act a certain way, but they're programmed so they will always act that way.
The self-righteous and easily-annoyed robot at the beginning of "Nos-4-A2" will always be self-righteous and easily-annoyed. The vending machine in "The Slayer" who simply yells at common thugs, surrenders his soda to the real threats, and gives soda to little kids will ALWAYS yell at thugs, surrender soda to threats, and give soda to kids. (The fact that his washing machine wife says he "always" gives soda to kids indicates that this may be a permanent, hard-wired part of his manufactured personality.) There is a chance that, if that vending machine ran into Nos again, it would go "I have seen him before, giving him soda and shooting him did not work, so I will run," but this wouldn't constitute a huge change in his personality. More likely, he would go "Oh man, YOU again?!" and try the same techniques, realizing that they would probably fail--because that's what he's programmed to do, and thus, that's all he knows how to do.
Whereas XR actually learns from experiences. He saps Nos's energy with his finger-suction-cups once, and goes hey, I can do it again. What's more, that forms a minor change in his personality: the next time he runs into Nos, he doesn't scream in terror and run like crazy, but cockily attempt to power Nos down with his finger-suction-cups again. And when that doesn't work, he doesn't try again, but freaks out and tries to run again, and doesn't try the power-down tactic again. Both XR and the vending machine speak and behave in ways indicative of a personality; but whereas XR developed his personality on his own, and at times we can see his personality grow and change, the vending machine may well have his personality hard-wired and unchangeable--either that, or only slightly changeable.
As for Nos, he could easily be an "unchanging" robot. Does his personality really change over the course of the series? Sure, after his first episode, he doesn't make another direct attack on Star Command, but he may well have been working his way back towards it, except more carefully. Or maybe taking over Star Command was his primary programmed function, but he may also have been programmed to cause general mayhem wherever he was. Or, he may not have specifically been programmed to take over Star Command at all, but had merely received an order to do so; and when he failed to do so, his programming regarded that particular order as terminated, so he deleted it and went off to do his own thing. OR, because he was not programmed to be defeated (as he says), he had no data on what to do if he were defeated, and so everything he does past the first episode is the result of a glitched/broken/corrupted program in his system, culminating with his decision to usurp Zurg. (It's like dividing by zero! Causes all sorts of trouble in computers!)
On the XL issue: perhaps XL really did have the same programming as XR, but when the LGMs introduced XR, they just pretended XL never happened. That wouldn't surprise me, since they seem really, really embarrassed about the incident. When Buzz first questioned a few about XL, they quickly left. If XL had the same "watch and learn" programming, and if what he watched and learned at the outset was, say, a bunch of Rangers shooting Hornets, for which Nebula congratulated them (or some situation like that), that could have taught him that the meaning of life was taking out his guns and shooting things, which is what we see him doing in his flashback. The LGMs may have decided that XL just doesn't count.
A slightly alternate theory to the stuff I threw out above. Thinking about the point when XR was originally built... When the LGMs said that XR was one of a kind, maybe they meant the fact that he was COMPLETELY a blank slate, with absolutely NO personality whatsoever, and the capability to grow a personality later? That way, we could say that other robots can still have "evolving" personalities, so we can say that it'd be plausible for the vending machine to be traumatized for life and to learn to run next time he sees Nos--other robots can change their personalities. But the difference between them and XR is that they were designed with a base personality (with the potential, possibly, for their personalities to change later), but XR was special because he had NO personality and developed a FULL one. So it's like he started at 0% personality and went to 100%, while other robots with pre-designed personalities can go from 60% to 100%--or, maybe, since they're restricted by their base programming, only from 60% to 80%, since they can never really develop fully independent personalities.
This would also explain the changes in Nos's behavior over the course of the series (this is him starting at 60% and going to 80-100%), while his basic personality never really changes at all, while XR's fluctuates more widely. And XL's fluctuates a lot as well: he goes from jealous, vengeful, moody, and violent, to an apparently happy copy machine. (I still maintain that XL started out basically the same as XR, but the LGMs like to pretend he didn't happen when they talk about XR.)
@levy, how exactly did Nos's "cannot be defeated" program mess up? Yes, he DID get defeated, but that wasn't because Nos himself did anything incorrect; it was the actions of the characters around him that resulted in his defeat. Saying that Nos's "cannot be defeated" program got messed up because he was defeated would be like saying that if you instruct a TiVo to tape a show on channel 900, the TiVo's programming is messed up if it doesn't record the show because your house doesn't have cable. The program itself is just fine: it's the circumstances in the world outside of the machine that prevent the program from executing properly.
TL;DR: HERE'S THE ABBREVIATED VERSION. Maybe the LGMs didn't meant that XR was the first robot to have a personality; he was just the first robot with the ability to develop a personality from scratch. Other robots have personalities programmed into them, but they can't start personality-free and grow their own personality like XR. In the case of XL, maybe he had the same program as XR, but since the LGMs like to deny that project, they just pretend he didn't exist when they talk about how XR was the first one to function like this.
Now, as to the original question about how shoving random things in XR gave him a personality... ehhh, who knows. Chaos theory and luck, maybe. He just accidentally happened to have the exact wires crossed and the exact chips fried necessary to randomly produce the personality he now has. I dunno.
(P.S. Hello again for the first time in forever.)