I had to practice many concepts in Natural Language Processing including "Generation of Text" using n-gram models. I'll be creating a general n-gram model to generate text. I found a good reference material uploaded on website of University of Pennsylvania. This was given as a Homework in UNiversity as CIS 521: Homework 7. Students and Teaching assistants can use it as a reference for teaching or study purposes. They are not supposed to use it or submit it as their Code. The reference link for the official document uploaded by university of Pennsylvania is is here: https://www.seas.upenn.edu/~cis521/Homework/homework7.html
Note: There are two files in repository. One is a .py file having all the functions needed to generate text along with code to test those functions at the end of file. One text file ( i.e. .txt file ) is also included in repository. ( You can use that given text file ) or use some other text to test n-gram models.