← All notes

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

Sources

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

Permanent ID: iil:note:beqgp6ke

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

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-randv2.md.