The independent variable is what the investigator varies; the dependent variable is the measured outcome. A confound varies with the conditions and offers an alternative explanation. Random assignment helps make groups comparable within a study. Random sampling addresses who is represented. A correlation by itself does not settle the direction of causation.
Worked example
Spot what changed along with the treatment
All students using study method A are tested in the morning; all students using B are tested at night. Scores differ. Can the difference be pinned on the study method?
No. Test time varies with the method. Assign students to conditions and keep test timing comparable, or vary timing separately so the effects can be distinguished.