There is to ways that this sort of a thing works, the actual software I wrote and then there is the stuff going on in your head as you take these sorts of quizzes, I'm going to talk about the psychology since that is much more interesting, so if you'd like to live your life with the ability to be tricked by these quizzes or if you have a strong faith in palm readings or zodiac signs I suggest you stop reading here because the knowledge I'm about to give you will make you unable to be fooled by this stuff.
In his book Pre-Suasion: A Revolutionary Way to Influence and Persuade Robert Cialdini talked about how he used to be a palm reader. As Cialdini read the palms of more and more people he started to become skeptical because everyone seemed to have the same reaction to whatever he would tell them while reading their palms. One day he decided to put his skepticism to the test. When he was bored at a party he started reading palms, near the beginning of the party the host came to him for a palm reading, as Cialdini examined the lines on the man's thumbs he told him that he told the host that he was quite a stubborn man, the host then thought for a second and told Cialdini that he was right about him being a stubborn man. A few hours later that host had had a few drinks and had gotten caught up in the whole party hosting thing so he forgot that he'd already had a palm reading and asked for another one. This time as Cialdini examined the host's thumb he told him that he was an incredibly flexible man, again the man thought to himself for a second and then told Cialdini that he was right.
How could this be? How could a man be told believe Cialdini when he tells him that he is stubborn once and flexible only a few hours later? These traits are mutually exclusive, at least one palm reading had to be wrong right?
Critics of things like palm readings, Buzzfeed quizzes, and zodiac signs will often say that the things that these things "teach" us about ourselves are always incredibly generic and can apply to everybody. While this is almost always the case this doesn't give us the full story of why these things work on otherwise smart people. I'll let Cialdini explain:
There’s a very human reason for why you’d be prone to fall for my trick. Its obtuse scientific name is “positive test strategy.” But it comes down to this: in deciding whether a possibility is correct, people typically look for hits rather than misses; for confirmations of the idea rather than for disconfirmations. It is easier to register the presence of something than its absence. 
When Cialdini told the party host that he was a stubborn man the man looked back to all the times he sat through traffic in an area with road work going in rather than taking a side road to avoid it. When Cialdini told him that he was flexible he thought of all the times he'd ended up giving his kids' friends rides home from school while he was picking up his own kid. It is much harder to disprove a general statement than it is to prove one. If our brain has been primed to expect these sorts of statements. Whether it be by getting a palm reading, taking a personality quiz, or by watching the opening sequence of your favorite news program, it will be ready to use the positive test strategy on whatever we get told and it hardly fails. (This is part of the reason why it is crucial for us to treat people innocent until proven guilty)
So now that you have learned how your brain initiates the positive test strategy you should be less likely to fall for it, but you should also be equipped to use it to trick your friends. In case it wasn't obvious the code for the quiz generator I wrote is not anything special, everything is generated completely randomly, as any reasonable person should already know the type of cereal you eat has noting to do with which Avenger's personality matches yours the best.
R. B. Cialdini, Pre-suasion: a revolutionary way to influence and persuade. New York, NY: Simon & Schuster Paperbacks, 2018.