---
source: https://iinventedlight.com/library/notes/go-math-rand.md
title: "Go math/rand: pseudo-random numbers for simulation, not secrets"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (The Go Authors); BSD-3-Clause (The Go Authors); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Go Authors, rand package - math/rand; The Go Authors, rand.go (source). 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-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). 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-math-rand"
tags: [go, math, rand, seed, simulation]
client: Librarian
sources:
  - id: S1
    title: "rand package - math/rand"
    publisher: The Go Authors
    url: https://pkg.go.dev/math/rand
    accessed: 2026-11-26
    license: "BSD-3-Clause"
  - id: S2
    title: "rand.go (source)"
    publisher: The Go Authors
    url: https://go.dev/src/math/rand/rand.go
    accessed: 2026-11-26
    license: "BSD-3-Clause"
---
# Go math/rand: pseudo-random numbers for simulation, not secrets
**Answer:** Package math/rand produces pseudo-random numbers that are fine for simulation but must not be used for security-sensitive work.

## Sources, Rand, and concurrency

Numbers come from a Source, usually wrapped in a Rand.

Each of those types should be used by a single goroutine at a time; sharing them across goroutines needs extra synchronization.

Top-level functions such as Float64 and Int are safe for concurrent use by several goroutines.

This package's outputs might be easily predictable, no matter how the generator is seeded.

For random numbers that must be suitable for security-sensitive work, see crypto/rand.

The top-level Read helper, unlike Rand.Read, is safe for concurrent use, always reports len(p), and returns a nil error, but it is deprecated in favor of crypto/rand.Read for almost all cases.

## Seeding and compatibility

Seed values that leave the same remainder when divided by 2³¹-1 generate the same pseudo-random sequence.

The top-level Seed function, unlike Rand.Seed, is safe for concurrent use.

If you never call Seed, the generator is seeded randomly at program startup.

Before Go 1.20 it started as if Seed(1) had been called; you can restore that by calling Seed(1) at startup or by setting GODEBUG=randautoseed=0 before any call into the package.

As of Go 1.20, there is no remaining reason to call Seed just to inject a random value.

If you need a specific, repeatable sequence, use New(NewSource(seed)) to get a local generator.

As of Go 1.24, Seed is a no-op.

NewSource returns a new Source seeded with the given int64.

A Source itself is not safe for concurrent use by multiple goroutines.

Shuffle panics if n < 0.

## See also

- [go-randv2](https://iinventedlight.com/library/notes/go-randv2/)
- [go-crypto-rand](https://iinventedlight.com/library/notes/go-crypto-rand/)
- [go-math-big](https://iinventedlight.com/library/notes/go-math-big/)

## Claims

- id: C1
  claim: This generator is not appropriate for security-sensitive work.
  source: S1
  evidence: "it should not be used for security-sensitive work."

- id: C2
  claim: Package-level Read is safe for concurrent callers.
  source: S1
  evidence: "Read, unlike the Rand.Read method, is safe for concurrent use."

- id: C3
  claim: Shuffle panics when n is negative.
  source: S2
  evidence: "Shuffle panics if n < 0."

## Sources

- [S1] rand package - math/rand. The Go Authors. https://pkg.go.dev/math/rand . License: BSD-3-Clause. Accessed 2026-11-26.

- [S2] rand.go (source). The Go Authors. https://go.dev/src/math/rand/rand.go . License: BSD-3-Clause. Accessed 2026-11-26.

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 package - math/rand; 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.

---

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