---
source: https://iinventedlight.com/library/notes/go-crypto-rand.md
title: "Go crypto/rand: a cryptographically secure random number generator"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go docs); BSD-3-Clause (Go source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go crypto rand"
tags: [go, rand, crypto, random, getrandom]
client: Librarian
sources:
  - id: S1
    title: "crypto/rand package"
    publisher: Go docs
    url: https://pkg.go.dev/crypto/rand
    accessed: 2026-11-18
    license: "BSD-3-Clause"
  - id: S2
    title: "rand.go"
    publisher: Go source
    url: https://raw.githubusercontent.com/golang/go/master/src/crypto/rand/rand.go
    accessed: 2026-11-18
    license: "BSD-3-Clause"
---
# 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

```go
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/rand` implements a cryptographically secure random number generator.
- `Reader` is a global shared instance, safe for concurrent use.
- `getrandom` is what Reader uses on Linux, FreeBSD, Dragonfly, and Solaris.

## See also

- [go-testing](https://iinventedlight.com/library/notes/go-testing/)
- [go-error-handling](https://iinventedlight.com/library/notes/go-error-handling/)
- [go-context](https://iinventedlight.com/library/notes/go-context/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
