There aren't many things harder to do than to ask someone to put their own reputation on the line to promote you. So to make things easier, always remember the following points:
Start off by listing professors who have an intimate relationship with your work. Make sure the work you have done for them has always been excellent, or at least above average;
When you ask, still make sure you ask for a positive letter of recommendation, so that they can tell you from the beginning if they plan to give you positive feedback. They should be able to give a detailed letter that is at once sincere and serious, and it should show support for whatever you are applying for;
Letters with any kind of generic structures won’t do you any good, because they don't show much about your special abilities and talents. Make sure to be polite and informative of exactly what you want out of this letter so that everything is clear and the letter is all it can be to ensure you get the position (or get into the program) that you are aiming for.
Hopefully this answers your question of how to ask a professor for a letter of recommendation.