In the past decades, there has been much interest in the elasticity of infrastructures to targeted and random attacks. In the recent work by Schneider C. M. et al., Proc. Natl. Acad. Sci. U.S.A., 108 (2011) 3838, the authors proposed an effective measure (namely R, here we label it as Rt to represent the measure for targeted attacks) to evaluate network robustness against targeted node attacks. Using a greedy algorithm, they found that the optimal structure is an onion-like one. However, real systems are often under threats of both targeted attacks and random failures. So, enhancing networks robustness against both targeted and random attacks is of great importance. In this paper, we first design a random-robustness index (Rr). We find that the onion-like networks destroyed the original strong ability of BA networks in resisting random attacks. Moreover, the structure of an Rr-optimized network is found to be different from that of an onion-like network. To design robust scale-free networks (RSF ) which are resistant to both targeted and random attacks (TRA) without changing the degree distribution, a memetic algorithm (MA) is proposed, labeled as MA-RSFTRA. In the experiments, both synthetic scalefree networks and real-world networks are used to validate the performance of MA-RSFTRA. The results show that MA-RSFTRA has a great ability in searching for the most robust network structure that is resistant to both targeted and random attacks.