USN/USMC was to a degree a little less arbitrary.
Originally, the squadron designator for Naval (carrier-borne) aircraft indicated their "home" carrier.
IE:
VF-6, VT-6, VS-6 and VB-6 were all based aboard USS Enterprise, CV-6. The squadron designated matched the hull number of the carrier.
However wartime attrition, both in aircraft and ships, and the needs of reassigning squadrons to where they were needed disrupted this (for example, by Guadalcanal VF-6 had been replaced by VF-10 aboard Enterprise).
In the case of the USMC...
Note that USMC squadrons tended to carry three-digit designations. Before the war, the first two digits indicated the air group, while the third indicated the squadron.
So, VMF-232 would have before the war been assigned to MAG-23, and was the second squadron (MAGs generally were comprised of four squadrons).
However like with the USN, combat needs led to squadrons being reassigned, folded into others, and outright disbanded and replaced so that the designation scheme was largely abandoned (generally the Marines still kept the three-digit squadron designations)