Owing to their structural diversity, RNAs perform many diverse biological functions in the cell. RNA secondary structure is thus important for predicting RNA function. Here, we propose a new combinatorial optimization algorithm, named RGRNA, to improve the accuracy of predicting RNA secondary structure. Following the establishment of a stempool, the stems are sorted by length, and chosen from largest to smallest. If the stem selected is the true stem, the secondary structure of this stem when combined with another stem selected at random will have low free energy, and the free energy will tend to gradually diminish. The free energy is considered as a parameter and the structure is converted into binary numbers to determine stem compatibility, for step-by-step prediction of the secondary structure for all combinations of stems. The RNA secondary structure can be predicted by the RGRNA method. Our experimental results show that the proposed algorithm outperforms RNAfold in terms of sensitivity, specificity, and Matthews correlation coefficient value.