I'm sure it uses an RNG.
RNG stands for random number generator. It might be like this-
1 = Cheren
2 = Roxie
3 = Burgh
4 = Elesa
and so on.
The limit 8 since there are 8 Unova leaders.
So maybe the game chooses the first match to be 1, the second to be 8 and the third to be 3, then you would face Cheren first, Marlon second and Burgh third.