Skip to content
go-libfossil Artifact [9af404eba1]
Login

Artifact [9af404eba1]

Artifact 9af404eba1cd668bffdf95a28660b785353605412900359c615864c2bd5a2127:


package simio

import (
	"crypto/rand"
	"io"
	mrand "math/rand"
)

// Rand abstracts random byte generation for deterministic simulation.
type Rand interface {
	Read(p []byte) (n int, err error)
}

// CryptoRand delegates to crypto/rand (production use).
type CryptoRand struct{}

func (CryptoRand) Read(p []byte) (int, error) { return rand.Read(p) }

// SeededRand uses a seeded math/rand source for deterministic output.
type SeededRand struct {
	src io.Reader
}

func NewSeededRand(seed int64) *SeededRand {
	return &SeededRand{src: mrand.New(mrand.NewSource(seed))}
}

func (r *SeededRand) Read(p []byte) (int, error) {
	return r.src.Read(p)
}