In eth2 validators will be randomly selected. What is the formula for how this random selection works?
Validators are not randomly selected, anyone/thing with 32 ETH is eligible to become an Eth2 validator.
However, once a validator (represented by a BLS public key) becomes active, they are randomly selected to perform tasks on the beacon chain. There are two primary tasks:
- Producing blocks: the compute_proposer_index function uses entropy from randao reveals from previous blocks (and an eth1 block hash) to elect validators to produce blocks at certain heights in the beacon chain (these heights are known as "slots" in eth2).
- Producing attestations: the get_beacon_committee function uses the same randao reveals to assign groups of validators into "committees" that must create attestations (votes) about the history of the beacon chain. In phase 1/2, these committees will likely also attest to properties of shard chains.
Cavet: the Eth2 spec is still evolving, this answer references spec v0.11.1 from April 2020