My understanding is that MJ, being dioecious (spelling?), does not have 100% pre-determined male or female flowers in the seed. Granted, the seed (genes) holds factors that , upon germination, increases the probability that male, female, or both types of flowers will be expressed. Then, as the seed germinates and lives in its veg stage, environmental factors either increase the base probabilities of flower types or decrease the probability. In flowering when hormones start seriously moving, the plant bathes cells in hormones that make them grow into either stamen or pistil bearing flowers. In some plants, you get cells bathed in both, and end up with both (hermes). Genetics AND environment contribute to the sex. There are many posts here that give tips and tricks to help you manage the environmental factors and increase the likelihood that your plant wants to make female flowers instead of male flowers. (i.e. temp, nutrients, ph, etc)
Note: According to Ed Rosenthal, in his book Closet Cultivator, there are some indica varieties that will produce random male flowers at the very end of ripening. Ed considers this a sign that the bud is ripe. (i.e. You'll see a few male flowers starting on nugget tips, but the bud is already 50% to 80% ripe is my applied interpretation). I have a plant that is doing just this, and truly it worries me not at all because by the time the male parts pop open (there may be 1 or 2 on a 6" cola one even has 3!), I'll be picking the bud in 5 days, so even if a flower gets pollinated, it won't live long enough to worry about it getting seedladen.