When an epoch starts, initially 21 masternodes (this number can be changed by network proposal) are randomly chosen to be the validators for that epoch according to the previous hash. A masternode can be chosen to be a validator more than 2 times in a row.