Foal traits are almost all determined from their parents. There is a complex system of genetics that determines everything you see, and many things you don't see, about a horse. A basic knowledge of genetics will help you understand what your foal may end up with, but there are also tools you can use to help you get a better picture. In general, one allele from each parent is given to the foal, so each foal gene is half from the sire and half from the dam. If the sire has a dirt gene of Dd and the dam has a dirt gene of DD, the sire could pass a D or a d, but the dam can only pass a D. The results in the foal would be either Dd or DD.
There is an entire guide about the different genes and traits in FFH, which you are encouraged to read. Though you can certainly play the game without understanding this in detail, it will help you make the most of your breedings and understand why your foals come out the way they do.
In a nutshell, very little on FFH is completely randomized! Foals stats and genes pass directly from the parents, and only a few "personality" type traits - like mud tolerance, equipment preferences, etc. are randomly determined.¸
Aside from the basic genetics, there are a few things that directly impact the racing quality of foals - also known as their stats. The first and foremost is the producer quality of the parents. Some stallions, no matter how good they look on paper, will simply not live up to expectations and will throw a lot of rather bad foals. While mares have producer quality as well, the quality of the stallion bears more weight in the equation. Thus it's always to your benefit to look for stallions who have a strong family history of being good producers. Even then, you may still find a dud.
The second important factor in breeding, beyond genetics, is bloodline. There is an entire section about this in the handbook, which goes into more detail. In a nutshell, the closer a sire and dam's blood types are to each other, the better the foal will be. Good producers can still throw nice foals even with questionable bloodline crosses, but it's in your best interests to try to match bloodlines as best as possible. They don't need to be exact, just close!
Conformation also has a chance to give a slight increase or decrease to a foal's stats at birth. This is not drastic and will definitely not impact stats as much as other factors (stat genes, bloodline, producer quality), but will be something to keep in mind. Lower conformation will have higher odds of reducing stats than high conformation will have of increasing them.
Inbreeding penalties are a real thing with foals! All horses have been assigned an inbred percentage similar to the custom percentage. The penalties for inbreeding will not be too drastic unless the horse is 50% inbred (has the same grandsire or grand dam on both sides).