I know that there is a link between CPs and predetermined IVs in these situations
These IVs are not "predetermined"; they have a more limited range (each IV must be at least 10), but they otherwise are random draws upon hatch/raid completion. They're not related to the CP of the Pokémon you fight in the raid; those CP (and the IV underlying them) are fixed.
The fact that you got two identical Darkrai and two identical Magikarp is just happenstance, nothing more. The odds are 1/(6^3), or 1/216, of that happening (of the next Darkrai having the identical IVs of the last one you caught).
The CP formula is as such:
See this Pokemon Go Hub article for more details on how CP is calculated. These values (attack, defense, stamina) are specific to the Pokémon, and each one has a "base" set of A/D/S values that are what a 0/0/0 Pokémon would have, plus the IV value. They go up with level, as does the CPM value (which is an arbitrary value used to make the CPs scale the way Niantic wants them to). The IVs don't actually matter very much - as an example, a level 30 Machamp would have an Attack of 234, so the attack IV would take it from 234 to 249. Not a huge difference, after all. The level and the base stats make far more difference.