rand

package
v0.0.0-...-79bd843 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package rand provides a random number source abstraction for UMAP.

In production, Source wraps math/rand/v2. In tests, a Recorded source plays back prerecorded sequences from the Python reference implementation, enabling byte-for-byte reproducibility verification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Production

type Production struct {
	// contains filtered or unexported fields
}

Production wraps math/rand/v2.Rand as a Source.

func NewProduction

func NewProduction(seed *uint64) *Production

NewProduction creates a new production random source from a seed. If seed is nil, uses an auto-seeded source.

func (*Production) Float64

func (p *Production) Float64() float64

func (*Production) Intn

func (p *Production) Intn(n int) int

func (*Production) NormFloat64

func (p *Production) NormFloat64() float64

func (*Production) Perm

func (p *Production) Perm(n int) []int

func (*Production) UniformFloat64

func (p *Production) UniformFloat64(low, high float64) float64

type Recorded

type Recorded struct {
	// contains filtered or unexported fields
}

Recorded plays back prerecorded random sequences. It panics if more values are consumed than were recorded, indicating a divergence between Go and Python call order.

func NewRecorded

func NewRecorded(data RecordedData) *Recorded

NewRecorded creates a Recorded source from a RecordedData struct.

func NewRecordedFromFile

func NewRecordedFromFile(path string) (*Recorded, error)

NewRecordedFromFile loads a Recorded source from a JSON file.

func (*Recorded) Float64

func (r *Recorded) Float64() float64

func (*Recorded) Intn

func (r *Recorded) Intn(n int) int

func (*Recorded) NormFloat64

func (r *Recorded) NormFloat64() float64

func (*Recorded) Perm

func (r *Recorded) Perm(n int) []int

func (*Recorded) Remaining

func (r *Recorded) Remaining() (ints, floats, norms, perms int)

Remaining returns the number of unconsumed values in each sequence.

func (*Recorded) UniformFloat64

func (r *Recorded) UniformFloat64(low, high float64) float64

type RecordedData

type RecordedData struct {
	Ints   []int     `json:"ints"`
	Floats []float64 `json:"floats"`
	Norms  []float64 `json:"norms"`
	Perms  [][]int   `json:"perms"`
}

RecordedData holds prerecorded random sequences from the Python reference implementation. Each field is a sequence of values consumed in order.

type Source

type Source interface {
	// Intn returns a random int in [0, n).
	Intn(n int) int

	// Float64 returns a random float64 in [0.0, 1.0).
	Float64() float64

	// NormFloat64 returns a normally distributed float64 (mean=0, stddev=1).
	NormFloat64() float64

	// Perm returns a random permutation of [0, n).
	Perm(n int) []int

	// UniformFloat64 returns a random float64 in [low, high).
	UniformFloat64(low, high float64) float64
}

Source provides all random operations UMAP needs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL