Standard commentarial teaching is:
1) We lived infinite amount of times. Enough times that the blood, tears, etc we shed filled 4 oceans and been in many different situations. SN15.x
2) Because of the above, we have over this infinity committed every kind of mundane kamma possible in infinite amount.
3) Question: Since kusala/akusala kamma done aeons ago can play out today, what determines which kammavipāka will mature today? It almost seems like it could be any mundane kamma result (see #2).
So kamma as explanation of "why bad things happen to good people" runs into this difficulty of randomness or equality. Over infinite time span, mundane kamma that you have done is overally the same as kamma that I have done, thus it cannot be a basis for distinction about what happens today. Also when it comes to rebirth:
Daṇḍa sutta SN15.9 states that:
"Just as a stick thrown up in the air lands sometimes on its base, sometimes on its side, sometimes on its tip; in the same way, beings hindered by ignorance and fettered by craving, transmigrating & wandering on, sometimes go from this world to another world, sometimes come from another world to this."
It appears to be somewhat random, unless one becomes an Aryan which would exclude rebirth in lower realms - but not kammavipāka playing out in this life.