Skip to content

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).
using System;
using System.Linq;

namespace LoremIpsum;

public static class Lorem
{
    // The canonical word pool — identical across every port.
    static readonly string[] 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(' ');

    static readonly Random Rng = new();  // non-crypto, matching the TS source

    // Uniform integer in [0, max); 0 for a non-positive bound.
    static int RandBelow(int max) => max <= 0 ? 0 : Rng.Next(max);

    // One capitalized sentence of minWords..maxWords random words.
    public static string Sentence(int minWords = 8, int maxWords = 16)
    {
        int span = Math.Max(1, maxWords - minWords + 1);
        int n = minWords + RandBelow(span);
        string body = string.Join(' ', Enumerable.Range(0, n).Select(_ => Words[RandBelow(Words.Length)]));
        // Capitalize the first character only — char.ToUpper leaves the tail alone.
        // A zero-word body (minWords 0) degrades to ".", matching the TS source.
        return body.Length == 0 ? "." : char.ToUpper(body[0]) + body[1..] + ".";
    }

    public static string Paragraph(int sentences = 5) =>
        string.Join(' ', Enumerable.Range(0, sentences).Select(_ => Sentence()));

    public static string Text(int paragraphs = 3, int sentencesPerPara = 5) =>
        string.Join("\n\n", Enumerable.Range(0, paragraphs).Select(_ => Paragraph(sentencesPerPara)));
}

public static class Program
{
    public static void Main() => Console.WriteLine(Lorem.Text());
}

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 →