Code Monkey home page Code Monkey logo

lipsum's Introduction

Lorem Ipsum

Lipsum is a small Rust library for generating pseudo-Latin lorem ipsum filler text. This is a standard placeholder text used in publishing. It starts with:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat…

The text is generated using a Markov chain that has been trained on the first book in Cicero's work De finibus bonorum et malorum (On the ends of good and evil), of which the lorem ipsum text is a scrambled subset.

Usage

Add this to your Cargo.toml:

[dependencies]
lipsum = "0.9"

Documentation

Please see the API documentation.

Getting Started

Use the lipsum function to generate lorem ipsum text:

use lipsum::lipsum;

fn main() {
    // Print 25 random words of lorem ipsum text.
    println!("{}", lipsum(25));
}

This generates the lorem ipsum text show above:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco…

The text becomes random after 18 words, so you might not see exactly the same text.

Use lipsum_title instead if you just need a short text suitable for a document title or a section heading. The text generated by that function looks like this:

Refugiendi et Omnino Rerum

Small words are kept uncapitalized and punctuation is stripped from all words.

Release History

This is a changelog with the most important changes in each release.

Version 0.9.1 (2024-03-13)

  • #100: Add lipsum_title_with_rng function.
  • #102: Document MSRV in Cargo.toml.
  • #103: Enable dependabot updates.

Version 0.9.0 (2023-03-28)

  • #90: Test minimum supported Rust version (Rust 1.56) in CI
  • #91: Remove dependency on system randomness

Version 0.8.2 (2022-06-06)

  • #84: Fix build error on Rust 1.56. Thanks @WorldSEnder for the report.

Version 0.8.1 (2022-04-19)

  • #73: Add lipsum_from_seed and tweak capitalization. Thanks @reknih!
  • #77: Update to Rust 2021 edition.

Version 0.8.0 (2021-05-30)

The random number generator has been separated from the MarkovChain implementation to allow using the same trained model to generate multiple outputs with different seeds. Thanks @Diggsey!

Version 0.7.0 (2020-07-08)

  • The code has been updated to the Rust 2018 edition.

  • Each new release will only support the latest stable version of Rust. Trying to support older Rust versions has proven to be a fool's errand: our dependencies keep releasing new patch versions that require newer and newer versions of Rust.

  • #65: A new lipsum_words_from_seed function was added. It generates random but deterministic lorem ipsum text. This is useful in unit tests when you need fixed inputs.

Version 0.6.0 (2018-12-09)

The new lipsum_words function can be used to generate random lorem ipsum text that doesn't always start with "Lorem ipsum".

Dependencies were updated and the oldest supported version of Rust is now 1.22.

Version 0.5.0 (2018-04-22)

The new lipsum_title function can be used to generate a short string suitable for a document title or a section heading.

Dependencies were updated and the oldest supported version of Rust is now 1.17.

Version 0.4.0 (2017-09-24)

The generate and generate_from now always generate proper sentences, meaning that they generate sentences that start with a capital letter and end with . or some other punctuation character. Use iter and iter_from directly if you need more control.

Version 0.3.0 (2017-07-28)

Performance is improved by about 50% when generating text, but training the Markov chain now takes about twice as long as before.

The MarkovChain struct has many new methods:

  • new_with_rng makes it possible to specify the random number generator used by the Markov chain. Use this to get deterministic and thus reproducible output for tests. MarkovChain now owns the RNG it uses and as a consequence, it has an extra type parameter. This is a breaking change if you used struct directly in your code.

  • iter and into_from return iterators over words in the Markov chain. The generate and generate_from methods are now straight-forward convenience wrappers for the iterators.

  • len tells you the number of stats in the Markov chain and is_empty tells you if the Markov chain is empty, meaning that it hasn't been trained on anything yet.

Version 0.2.0 (2017-07-10)

Rust version 1.6.0 is now supported. This is checked with TravisCI.

Version 0.1.0 (2017-07-2)

First public release.

License

Lipsum can be distributed according to the MIT license. Contributions will be accepted under the same license.

lipsum's People

Contributors

dancespiele avatar dependabot[bot] avatar diggsey avatar mgeisler avatar reknih avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lipsum's Issues

New release

Would it be possible to make a new release? We would like to release Typst to crates.io, but can't because we depend on an unreleased change to lipsum.

Split model training from randomness

Training the model with "learn" is relatively slow (much slower than generating new words) so ideally you could train it once, and then use the same model to generate several sequences with different seeds.

However, this is not possible with the current API, because the seed is supplied when you first construct the MarkovChain, and cannot be changed after that point.

AFAICT, the "learn()" function is completely deterministic (it does not use the RNG) so this is a suboptimal design.

I would suggest removing the rng field from the MarkovChain entirely, and instead pass the RNG when you construct the Words iterator. This way you can train a model once, and then generate several sequences of text with different seeds. This should also make the lipsum_words_from_seed function much faster, even when not using a custom model.

not random

i thought it was going to be random text, but it generates the same thing every time per length.

println!("{}", lipsum(5));
println!("{}", lipsum(5));
println!("{}", lipsum(5));
println!("{}", lipsum(5));

Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet.

Clarify minimal support rust version

The recent update to 0.8.1 breaks when compiling with rust 1.56:

error[E0277]: expected a `Fn<(char,)>` closure, found `[char; 3]`
   --> src/lib.rs:350:52
    |
350 |             let mut needs_cap = sentence.ends_with(punctuation);
    |                                                    ^^^^^^^^^^^ expected an `Fn<(char,)>` closure, found `[char; 3]`
    |
    = help: the trait `Fn<(char,)>` is not implemented for `[char; 3]`
    = note: required because of the requirements on the impl of `FnOnce<(char,)>` for `&[char; 3]`
    = note: required because of the requirements on the impl of `Pattern<'_>` for `&[char; 3]`

error[E0277]: expected a `Fn<(char,)>` closure, found `[char; 3]`
   --> src/lib.rs:362:44
    |
362 |                 needs_cap = word.ends_with(punctuation);
    |                                            ^^^^^^^^^^^ expected an `Fn<(char,)>` closure, found `[char; 3]`
    |
    = help: the trait `Fn<(char,)>` is not implemented for `[char; 3]`
    = note: required because of the requirements on the impl of `FnOnce<(char,)>` for `&[char; 3]`
    = note: required because of the requirements on the impl of `Pattern<'_>` for `&[char; 3]`

error[E0277]: expected a `Fn<(char,)>` closure, found `[char; 3]`
   --> src/lib.rs:366:36
    |
366 |             if !sentence.ends_with(punctuation) {
    |                                    ^^^^^^^^^^^ expected an `Fn<(char,)>` closure, found `[char; 3]`
    |
    = help: the trait `Fn<(char,)>` is not implemented for `[char; 3]`
    = note: required because of the requirements on the impl of `FnOnce<(char,)>` for `&[char; 3]`
    = note: required because of the requirements on the impl of `Pattern<'_>` for `&[char; 3]`

For more information about this error, try `rustc --explain E0277`.

I'm not certain what's the underlying cause for this change (the repo is still tagged with rust 1.31, but reading #77 leads me to believe the tag is outdated). Most likely cause to me is this commit: 72c48a1

In any case, edition 2021 is part of 1.56.0 so at least that part shouldn't be an issue. Can you clarify the minimal supported compiler version, thanks :)


Breaking downstream CI: https://github.com/yewstack/yew/runs/6649247160?check_suite_focus=true#step:5:24

Feature for disabling system randomness?

Hi,
for my use case of lipsum, I exclusively call the ..._from_seed functions. Hence, I do not need the system-provided randomness through rand::thread_rng and the likes. The rand crate collects its seeds through its getrandom dependency.

I'm a big fan of lean binaries so I wondered whether you'd be willing to create a feature for system randomness (enabled by default). This way, users like me could turn this feature off and drop not only getrandom but also cfg_if (transitively).

Do you think this is a good idea, and if so, what should this feature be called? ("Randomness", "system-seeded", "getrandom" are a few examples coming to my mind.) I'd be happy to submit a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.