I found out what was going wrong with the code by testing it repeatedly, so unless you have altered something it should be working. Make sure you replaced all 3 lines from the original for loop.
If you have the Debug mod, then you can get some runtime feedback using detailed trace statements. I added
print("Attempt trait: ", i)
just under the for loop.
print("chance: ", chance, " roll:", roll)
Just before the final if statement in the loop.
print("Inherited trait")
Just after the baby inherits a trait