Luck. Gaining Legendary Weapons is completely random. I've seen people get them off of gravediggers and others off ghosts in Raven's Cove. You just need the luck of the draw to get your dream sword. Completing the raven's Cove quest will increase your likelyhood of gaining powerful weapons.