Go math/rand/v2: pseudo-random numbers for simulation, not security
Answer: The ChaCha8 source is a general-purpose source resistant to prediction.
What the package is for
Functions such as Float64 and Int are safe for concurrent use by multiple goroutines.
This package's outputs might be easily predictable regardless of how it's seeded.
Package rand implements pseudo-random number generators suitable for tasks such as simulation.
A Source is not safe for concurrent use by multiple goroutines.
Sources you can choose
Both types should be used by a single goroutine at a time.
Random numbers are generated by a Source, usually wrapped in a Rand.
The PCG source is faster but unfit for security-relevant purposes.
It should not be used for security-sensitive work.
See the crypto/rand package when you need numbers for security-sensitive work.
See also
Claims
- id: C1 claim: The ChaCha8 source is a general-purpose source resistant to prediction. source: S1 evidence: "The ChaCha8 source is a general-purpose source resistant to prediction."
- id: C2 claim: The PCG source is faster but unfit for security-relevant purposes. source: S1 evidence: "The PCG source is faster but unfit for security-relevant purposes."
- id: C3 claim: Both types should be used by a single goroutine at a time. source: S1 evidence: "Both types should be used by a single goroutine at a time"
- id: C4 claim: A Source is not safe for concurrent use by multiple goroutines. source: S2 evidence: "A Source is not safe for concurrent use by multiple goroutines"
Sources
- [S1] rand/v2 package reference. The Go Authors. https://pkg.go.dev/math/rand/v2 . License: BSD-3-Clause. Accessed 2026-11-24.
- [S2] rand.go source. The Go Authors. https://go.dev/src/math/rand/v2/rand.go . License: BSD-3-Clause. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, rand/v2 package reference; The Go Authors, rand.go source. 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: The Go Authors, rand/v2 package reference; The Go Authors, rand.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go math/rand/v2: pseudo-random numbers for simulation, not security." iinventedlight Library, iil:note:beqgp6ke, version of 2026-11-24. https://iinventedlight.com/library/notes/go-randv2/. License: CC-BY-4.0.
@misc{iil_note_beqgp6ke,
author = {{iinventedlight}},
title = {{Go math/rand/v2: pseudo-random numbers for simulation, not security}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/go-randv2/},
note = {Permanent ID iil:note:beqgp6ke. 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-randv2.schema.json (schema; CC-BY-4.0)
- go-randv2.table.json (table; 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-randv2.md.