How are baking and endorsement rights allocated to bakers? Is there a formula? Can we see the distribution of the baking/endorsement rights for all bakers for each cycle? (Particularly for priority 0)
Baking and endorsing rights are allocated at random, proportionally to the delegate's stake, using a PRNG and a random seed derived from on-chain data (nonces committed by bakers and revealed later). For more details, see the doc.
To see the distribution of baking/endorsing rights, use these RPCs: