Lorem Ipsum Generator — Ruby source
Generate placeholder Lorem Ipsum text - paragraphs and sentences with adjustable counts. Classic Latin word pool, instant copy.
This is the Ruby implementation — the same logic the interactive tool runs, in a shareable, citable form.
# lorem-ipsum — Ruby port: canonical Lorem Ipsum generator (sentences, paragraphs, blocks).
# The canonical word pool — identical across every port.
WORDS = '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'.split(' ').freeze
# Uniform integer in [0, max); Kernel#rand is non-crypto, matching the TS
# source's Math.random().
def rand_below(max)
max <= 0 ? 0 : rand(max)
end
# One capitalized sentence of min_words..max_words random words.
def sentence(min_words: 8, max_words: 16)
span = [1, max_words - min_words + 1].max
count = min_words + rand_below(span)
body = Array.new(count) { WORDS.sample }.join(' ')
# Capitalize the first character only — String#capitalize would also
# lowercase the tail. The nil-guards make a zero-word body yield '.',
# matching the TS source's charAt(0) behaviour.
"#{body[0].to_s.upcase}#{body[1..].to_s}."
end
# sentences default-length (8..16 word) sentences joined by spaces.
def paragraph(sentences: 5)
Array.new(sentences) { sentence }.join(' ')
end
def lorem(paragraphs: 3, sentences_per_para: 5)
Array.new(paragraphs) { paragraph(sentences_per_para) }.join("\n\n")
end
puts lorem
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 →