← All notes

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

See also

Claims

Sources

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

Permanent ID: iil:note:v2gsqeme

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.},
}

Markdown

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.

All artifact files (JSON index)

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.