Disclosed is a method of altering a nucleic acid such as RNA or DNA. The method comprises fragmenting a parent nucleic acid strand to generate nucleic acid fragments. At least a subset of the fragments are ligated to generate shuffled nucleic acid strands. A selected strand is identified from the shuffled nucleic acid strands for a criterion. The methods of the invention can also be used to diversify proteins.