For beldum, what you said is correct in that you need a lot of good luck. If your definition of good is around 20 for each stat, then you basically need to hope your beldum gets those IVs. However, if you wanted perfect IVs, you will need to use a item called destiny knot which allows you to retain 5 random IV stats for your bred pokemon from the mother and father. As you can tell, it is preferable if your ditto does have great IVs beforehand which will speed up this process.
Legendaries can not be bred unless it is a manaphy which allows you to obtain phione. If you want a legendary wit