Skip to content

Commit

Permalink
Refactor sentence length bounds in init.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
derektata committed May 19, 2024
1 parent e7a2b5b commit 1cec3b3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lua/lorem/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ local _config = { sentenceLength = "mixedShort", comma = 0.1 }
local sentenceLengths = {
mixed = { 3, 100 },
mixedLong = { 30, 100 },
mixedShort = { 3, 30 },
mixedShort = { 1, 30 },
long = { 40, 60 },
medium = { 20, 40 },
short = { 3, 20 },
short = { 1, 20 },
}

-- Initialize the pseudo random number generator
Expand Down Expand Up @@ -79,8 +79,16 @@ source.gen_words = function(length)
end

local remainingSpace = length - textLength
if remainingSpace > 2 then
text = text .. source.gen_sentence(remainingSpace)
if remainingSpace > 0 then
if remainingSpace < lowerBound then
-- Generate exactly the number of words needed
for i = 1, remainingSpace do
text = text .. require("lorem.ipsum")()[math.random(1, #require("lorem.ipsum")())] .. " "
end
text = text:sub(1, -2) .. "."
else
text = text .. source.gen_sentence(remainingSpace)
end
end

return text
Expand Down

0 comments on commit 1cec3b3

Please sign in to comment.