Here's Pokemon Showdown's random battle generator: https://github.com/Zarel/Pokemon-Showdown/blob/d3ca5253bf5157b59004ae3a61496ecc10140824/mods/gen5/scripts.js
It seems to pick random moves from the viable moves list, and keeps track of the amount of damaging and status moves. It also has some things to make moves usable, for example only use Sleep Talk if Rest is generated.
The levels are set for each tier, like so:
'LC Uber': 86,
The EVs are 85 for all stats, and IVs are 31 for each stat.
It also has something to filter more than 2 of each type, and 1 for any type combination.
Past this, it has a counter for Uber and LC, NFE and NU pokes respectively (uber is one counter and the rest are another).
This tries to limit the amount of Ubers and NUs on one team to promote "fun":
LC Pokemon have a hard limit in place at 2; NFEs/NUs/Ubers are also limited to 2 but have a 20% chance of being added anyway.
LC/NFE/NU Pokemon all share a counter (so having one of each would make the counter 3), while Ubers have a counter of their own. ~Zarel
For the pokes themselves, a random number is most likely generated and the poke with the pokedex position of that number is selected.