Go's standard library is enough to build text adventures, turn-based games, quiz servers and multiplayer game backends. It is not a graphics or audio engine, so for 2D or 3D rendering you add a library such as Ebitengine, but game logic, timing, concurrency and networking all work with the standard packages.
This article shows how to use math/rand/v2, time, goroutines, net and net/http for the parts of a game that are not rendering.
Random events, loot tables and dice rolls come from math/rand/v2 (Go 1.22 and newer). Unlike the old math/rand, it is automatically seeded, so you no longer call rand.Seed. The Seed function in math/rand has been deprecated since Go 1.20.
The function does a weighted pick: rarer events get a smaller weight. For reproducible tests, create a generator with rand.New(rand.NewPCG(seed1, seed2)) and pass it around instead of using the global functions.
The math/rand packages are not cryptographically secure. Use crypto/rand for anything where players could profit from predicting the result, such as real-money drawings or session tokens.
Most games update state at a fixed rate. time.NewTicker gives you that rhythm, and context lets you stop the loop cleanly.
Using the same step for every update keeps the simulation deterministic, which matters for replays and for checking client moves on a server.
Goroutines let input, AI and timers run side by side. The safest pattern is to give one goroutine ownership of the game state and send everything else to it as messages, so you need no locks.
This is the skeleton of a text adventure: one reader goroutine and one loop that owns the state. The same shape scales to a server, where each connection goroutine sends commands into a channel read by a single game loop.
The net package gives you TCP and UDP listeners, and each accepted connection can run in its own goroutine. The server below echoes a reply to each line and handles errors and timeouts, which the common beginner version skips.
Test it with nc localhost 8080. For browser games, net/http serves the page and a JSON API. The standard library has no WebSocket implementation, so for real-time browser traffic you either use Server-Sent Events (supported by http.Flusher) or add a WebSocket library.
| Project | Standard packages | What to watch for |
|---|---|---|
| Text adventure | bufio, os, fmt | Keep state in a struct, not globals |
| Dice or card game | math/rand/v2 | Seed a generator for tests |
| Turn-based game server | net, encoding/json | Validate every client move on the server |
| Quiz or trivia site | net/http, html/template | Use html/template to avoid XSS |
| Leaderboard API | net/http, database/sql | Add rate limits and authentication |
| Save files | encoding/json, os | Write to a temp file, then rename |
You can generate images with image and image/png, but there is no window, input or audio API. Use a library such as Ebitengine for real-time 2D graphics.
No. Since Go 1.20 the global generator is seeded automatically and rand.Seed is deprecated. Prefer math/rand/v2, which has no Seed function.
Yes for most server-side work. Goroutines are cheap, and the garbage collector is tuned for low pause times, but profile your tick loop with pprof if frame budgets are tight.
Pass a context.Context to each goroutine and cancel it when the match finishes, and select on ctx.Done() alongside channel operations.
Go's standard library covers game logic (math/rand/v2, time), concurrency (goroutines, channels, context) and networking (net, net/http). Keep game state owned by one goroutine, use a fixed timestep, set connection deadlines, and add a third-party engine only when you need rendering, audio or WebSockets.