Lorem Ipsum Generator — C++ source
Generate placeholder Lorem Ipsum text - paragraphs and sentences with adjustable counts. Classic Latin word pool, instant copy.
This is the C++ implementation — the same logic the interactive tool runs, in a shareable, citable form.
// lorem-ipsum — C++ port: canonical Lorem Ipsum generator (sentences, paragraphs, blocks).
#include <algorithm>
#include <cctype>
#include <iostream>
#include <random>
#include <string>
#include <string_view>
// The canonical word pool — identical across every port.
constexpr std::string_view kWords[] = {
"lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit",
"sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et",
"dolore", "magna", "aliqua", "enim", "ad", "minim", "veniam", "quis",
"nostrud", "exercitation", "ullamco", "laboris", "nisi", "aliquip", "ex", "ea",
"commodo", "consequat", "duis", "aute", "irure", "in", "reprehenderit",
"voluptate", "velit", "esse", "cillum", "eu", "fugiat", "nulla", "pariatur",
"excepteur", "sint", "occaecat", "cupidatat", "non", "proident", "sunt",
"culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum",
};
// Mersenne Twister + uniform_int_distribution: unbiased picks, non-crypto —
// the C++ analogue of the TS source's Math.random().
class LoremGenerator {
std::mt19937 rng_;
int RandBelow(int n) { return std::uniform_int_distribution<>(0, n - 1)(rng_); }
public:
explicit LoremGenerator(unsigned seed = std::random_device{}()) : rng_(seed) {}
// One capitalized sentence of min_words..max_words random words.
std::string Sentence(int min_words = 8, int max_words = 16) {
const int span = std::max(1, max_words - min_words + 1);
const int n = min_words + RandBelow(span);
std::string body;
for (int i = 0; i < n; i++) {
if (i) body += ' ';
body += kWords[RandBelow(std::size(kWords))];
}
// Capitalize the first character only — the tail keeps its spelling.
if (!body.empty())
body[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(body[0])));
return body += '.';
}
std::string Paragraph(int sentences = 5) {
std::string out;
for (int i = 0; i < sentences; i++) {
if (i) out += ' ';
out += Sentence();
}
return out;
}
std::string Lorem(int paragraphs = 3, int per_para = 5) {
std::string out;
for (int i = 0; i < paragraphs; i++) {
if (i) out += "\n\n";
out += Paragraph(per_para);
}
return out;
}
};
int main() {
LoremGenerator generator;
std::cout << generator.Lorem() << '\n';
}
Also available in 13 other languages
Every CosmoDev tool ships its pure logic in TypeScript (web) and Go (CLI), with authored implementations in a dozen-plus languages — the same contract, ported. Compare all languages side by side →