Go crypto/rand: a cryptographically secure random number generator
Answer: Package rand implements a cryptographically secure random number generator. Reader is the shared global generator and is safe to use concurrently. On Linux, FreeBSD, Dragonfly, and Solaris, that Reader calls getrandom(2).
Examples
b := make([]byte, 16)
_, err := rand.Read(b)
Notes
On macOS, iOS, and OpenBSD, Reader uses arc4random_buf(3). On Windows it uses ProcessPrng.
Reference list
crypto/randimplements a cryptographically secure random number generator.Readeris a global shared instance, safe for concurrent use.getrandomis what Reader uses on Linux, FreeBSD, Dragonfly, and Solaris.
See also
Claims
- id: C1 claim: Reader is a global shared cryptographically secure generator. source: S1 evidence: "Reader is a global, shared instance of a cryptographically secure random number generator."
- id: C2 claim: It is safe for concurrent use. source: S1 evidence: "It is safe for concurrent use."
- id: C3 claim: On Linux, FreeBSD, Dragonfly, and Solaris, Reader uses getrandom(2). source: S2 evidence: "On Linux, FreeBSD, Dragonfly, and Solaris, Reader uses getrandom(2)."
Sources
- [S1] crypto/rand package. Go docs. https://pkg.go.dev/crypto/rand . License: BSD-3-Clause. Accessed 2026-11-18.
- [S2] rand.go. Go source. https://raw.githubusercontent.com/golang/go/master/src/crypto/rand/rand.go . License: BSD-3-Clause. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go docs, crypto/rand package; Go source, rand.go. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go docs, crypto/rand package; Go source, rand.go. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go crypto/rand: a cryptographically secure random number generator." iinventedlight Library, iil:note:v2gsqeme, version of 2026-11-18. https://iinventedlight.com/library/notes/go-crypto-rand/. License: CC-BY-4.0.
@misc{iil_note_v2gsqeme,
author = {{iinventedlight}},
title = {{Go crypto/rand: a cryptographically secure random number generator}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/go-crypto-rand/},
note = {Permanent ID iil:note:v2gsqeme. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-crypto-rand.table.json (table; CC-BY-4.0)
- go-crypto-rand.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-crypto-rand.md.