add sort by r
add rand* codes, and etc, left the model part