Lorem Ipsum generator using python

In this article, we will be using a python library called lipsum to generate random words and paragraphs. If you want to generate any random words, sentences, or paragraphs to populate your database with then this library is the way to go.

Installation

This library can be installed using pip from pypi.org as,

pip install lipsum

We can also download the source code from Github and install it by running the following command on the terminal.

python setup.py install

Once the installation is complete, we are good to go.

Examples

The following examples are dealt here.

  1. generate random words.
  2. generate random sentences.
  3. generate random paragraphs.

1. Generate random words.

The following code snippet gives an example of how to generate random words using this library. We can provide the number of words we want to generate as an argument to the generate_words() method.

generate random words

The output of this code is,

Sed cum ab his omnia proficiscantur officia, non sine causa dicitur ad ea referri omnes nostras cogitationes, in his et excessum e vita et in vita mansionem. in quo enim plura sunt quae secundum naturam sunt, huius officium est in vita manere; in quo autem aut sunt plura contraria au.

2. Generate random sentences

The following code snippet gives an example of how to generate random words using this library. We can provide the number of sentences we want to generate as an argument to the generate_sentences() method.

generate random sentence

The output of the above code is,

Lege laudationes, Torquate, noneorum, qui sunt ab Homero laudati, non Cyri, non Agesilai, nonAristidi aut Themistocli,non Philippi aut Alexandri, legenostrorum hominum, lege vestrae familiae; neminem videbis italaudatum, ut artifexcallidus comparandarum voluptatum diceretur. 
Non elogia monimentorum id significant, velut hoc ad portam: 'Huncunumplurimae consentiunt gentes populi primarium fuissevirum. 
'Idne consensisse de Calatinoplurimas gentis arbitramur, primarium populi fuisse, quodpraestantissimus fuisset inconficiendis voluptatibus?

Three sentences are generated as we have given the count as 3 to the generate_sentences method.

3. Generate random paragraphs

The following code snippet gives an example of how to generate random words using this library. We can provide the number of paragraphs we want to generate as an argument to the generate_paragraphs() method.

generate random paragraph

The output of the above code is,

Hoc ille tuus non vult omnibusqueex rebus voluptatem quasi mercedem exigit. sed ad illum redeo. sivoluptatis causa cum Gallo apud Anienem depugnavit provocatus et exeius spoliis sibi et torquem et cognomen induit ullam aliam obcausam, nisi quod ei talia facta digna viro videbantur, fortem nonputo. iam si pudor, si modestia, si pudicitia, si uno verbotemperantia poenae aut infamiae metu coercebuntur, non sanctitatesua se tuebuntur, quod adulterium, quod stuprum, quae libido non seproripiet ac proiciet aut occultatione proposita aut inpunitate autlicentia? Quid?

Illud, Torquate, quale tandemvidetur, te isto nomine, ingenio, gloria, quae facis, quae cogitas, quae contendis quo
referas, cuius rei causa perficere quae conarisvelis, quid optimum denique in vita iudices non audere in conventudicere? quid enim mereri velis, iam cum magistratum inieris et incontionem ascenderis - est enim tibi edicendum quae sis observaturusin iure dicendo, et fortasse etiam, si tibi erit visum, aliquid demaioribus tuis et de te ipso dices more maiorum - quid merearisigitur, ut dicas te in eo magistratu omnia voluptatis causafacturum esse, teque nihil fecisse in vita nisi voluptatis causa?'An me', inquis, 'tam amentem putas, ut apud imperitos isto modoloquar?'

we can also generate our own words by adding an additional parameter to the generate_paragraphs() method containing the path of the file.

generate random paragraph from a file

We can also set the encoding type for the paragraph.

Conclusion

Hope this article was helpful. Happy coding !