Many prescription pads have a way for the doctor to indicate if a brand name medication must be dispensed instead of the generic version (e.g. a line where they can write something like "brand necessary", "dispense as written", or "no substitution").
Why would it be necessary to prescribe a brand name medication if a generic version is available? According to the FDA:
Generic drugs are required to have the same active ingredient, strength, dosage form, and route of administration as the brand name product.
The FDA does say that "some variability can and does occur during manufacturing", but that applies to both generics and brand name medications:
These studies compared the absorption of brand name and generic drugs into a person’s body. [...] The average difference in absorption into the body between the generic and the brand name was 3.5 percent. Some generics were absorbed slightly more, some slightly less. This amount of difference would be expected and acceptable, whether for one batch of brand name drug tested against another batch of the same brand, or for a generic tested against a brand name drug. In fact, there have been studies in which brand name drugs were compared with themselves as well as with a generic. As a rule, the difference for the generic-to-brand comparison was about the same as the brand-to-brand comparison.
If the active ingredient is the same in both the brand name medication and the generic version, then the only difference is the inactive ingredients, which by definition do not affect the efficacy of the drug.