bash: sort files by a number inside them

I need to generate 100 .txt files with a random number inside each one of them. Then I need to rename the files so that the file names are named from 1.txt to 100.txt in ascending order based on the value that is stored inside each file. The file named 1.txt should have the smallest number stored in it and the file named 100.txt shouild have the largest number stored in it