You are trapped in a bar with fifty drunken angry Marines. Sometimes you get punched in the right side of your face, sometimes you get punched in the left side. Which outcome results from a particular interaction largely depends on whether it was more convenient for a given drunk to hit you from the right or left (which depends largely on your relative positions.)
Whether the R or S isomer of MDMA is formed in a given collision between imine and hydride (for instance) simply depends on the luck of the draw; if the hydrogen being added hits on one side of the imine you get one, if it hits on the other side you get the other. Although this is random, when you average it out over the hugenumbers of molecules involved in a given synthesis, you wind up with as close to 50:50 as makes no difference. There ARE reactions that favor one isomer or the other by making it easier for the reactants to run into each other from one side than the other. Failing that, isomers can be seperated (although usually not very easily) after synthing a racemic product.
'Stereoselective' synths (where one isomer is strongly favored over the other) are a bit on the exotic side as far as basic chemistry goes; none of the 'how to make drugs' synths on the internet are stereoselective. If you wanted one that is, you'd have to go digging into professional chemistry literature (if memory serves, Nichols may have developed a stereoselective MDMA synth.)