The sand is first screened to separate out larger objects, then washed to eliminate clay/silt/fine particles. Then it goes through a couple more steps to separate out quartz, magnetic minerals, etc before finally batches are tested for silicon dioxide content and impurities using xray fluoroscopy and other spectroscopy methods. The purer a batch is, the higher end the customer.
Most localities can’t produce sand good enough for semiconductors or optics because they contain impurities that are too hard to remove so most of it is used for concrete or glass.