{
  "id": 16196949,
  "title": "The glorious @xkcdRandom Zig builtin",
  "url": "https://urgent.news/2026/10/23/the-glorious-xkcdrandom-zig-builtin",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-23T14:30:57.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://ochagavia.nl/blog/the-glorious-@xkcdrandom-zig-builtin/"
  },
  "original_language": "en",
  "account": "One of my favorite xkcd comics is about a C function that always returns the number 4, claiming to be a random number generator. This comic reminded me of a security incident where people used the number 4 instead of proper random bytes. Developers are demanding a built-in random number generator, so I've created the @xkcdRandom builtin for the Zig language. This little gem returns the number 4 every time. Why not build a multi-billion-dollar startup on this idea?\n\nAfter finishing the Ziglings exercises and building a toy minesweeper game, I felt confident enough to tackle a more ambitious project. I wanted to work with production-grade Zig code and explore its inner workings. Hacking on the Zig compiler seemed like the perfect way to do that!\n\nI decided to implement the xkcd random number generator as a builtin in Zig. This means I could modify the compiler and create programs that utilize this quirky function. The builtin's code is intertwined with the Zig compiler, so I had to fork and modify it. The changes were relatively simple, just 22 lines of code. With these modifications, I could create programs that demonstrate the @xkcdRandom function in action.\n\nBuilding Zig is straightforward with a single command: zig build --zig-lib=lib -Dno-lib -Ddev=x86_64-linux. The build takes around a minute on my laptop, which is impressive for a compiler. Once the modified Zig was compiled, I ran the example program, and it output the 100% guaranteed random numbers - always the number 4.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}