Watching Band of Brothers, Saving Private Ryan, The Pacific, etc., I've always been curious as to what sorted certain soldiers to be riflemen, sub-machine-gunners, snipers, mortar-men, and such. Did a soldier place a preference? Was there a test given out to see how each person fared with each kind of weapon?
When a soldier enlisted voluntarily into the military or (later) was conscripted, he filled out a questionnaire that included information about what his job, and requisite skills, as a civilian was, if he had one. This job was used to assign the soldier a relevant Specification Serial Number and MOS, which denoted his "job" in the military. Examples include 2736 for a medium tank crewman, 745 for a rifleman, 746 for an automatic rifleman (BAR gunner), 345 for a truck driver, and 060 for a cook. SSNs below 500 had some parallel in civilian life, while SSNs above 500 were purely military jobs.
This situation did not always occur due to shortages in areas of the military determined through the relevant Tables of Organization and Equipment, and so a special formula developed by the office of the Secretary of the Army was used to randomly assign some soldiers their jobs, spitting out a combination of SSNs. For example, out of 1,000 men, it might say that 177.5 were to be truck drivers, and 49 were to be surgical technicians.
If a man was found to be unsuited for his assigned MOS, he was reclassified as 521, or "basic." This denoted a soldier who was in basic training, had received basic training but had not been to more advanced individual training, or was being reclassified to a new MOS. He was evaluated closely in his skills and tested frequently to determine which MOS might be best for him. Interestingly, the Tables of Organization and Equipment actually called for 521s sometimes, mostly in headquarters units. These men could be used as the unit commander saw fit, assisting other members of the unit such as clerks or cooks in their tasks, or performing menial work like hauling food, fuel, or ammunition.
Your MOS combined with the Table of Organization and Equipment of your assigned unit determined what weapons you would be issued during your service. There are a vast number of Tables of Organization and Equipment for different types of units, with soldiers in different units that perform the exact same role being armed differently. As a result I won't list them here. You will find many general commonalities across different units, however.
There are a very large number of original tables for various types of units transcribed onto PDF files listed here. Be warned that the tables sometimes do not tell explicitly which weapon each man has; Each chart contains two tables, one of men, and the other of equipment (mostly weapons) issued to the unit, so some very easy deductions may be necessary by comparing the tables of men and equipment.