pyrandom

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSampleSize = &pyint.Error{Kind: "ValueError", Msg: "Sample larger than population or is negative"}

ErrSampleSize is the ValueError random.sample raises for a k outside [0, n]

Functions

func Sample

func Sample[T any](r *Random, population []T, k int) ([]T, error)

Sample returns k distinct members of population in random.sample order

Types

type Random

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

Random is the Mersenne Twister generator behind Python random.Random

func New

func New(seed int64) *Random

Generator seeded with an integer the way random.seed(n) seeds it

func (*Random) GetRandBits

func (r *Random) GetRandBits(k int) *big.Int

Non negative integer of k random bits, words filled least significant first as getrandbits does

func (*Random) RandBelow

func (r *Random) RandBelow(n int) int

Uniform integer in [0, n) by rejection over n.bit_length() random bits

func (*Random) SampleIndices

func (r *Random) SampleIndices(n, k int) ([]int, error)

Indices of k distinct population members chosen as random.sample chooses them, pool or set selection by size

func (*Random) Seed

func (r *Random) Seed(seed int64)

Reseeds from the absolute value of seed split into little endian 32 bit words

Jump to

Keyboard shortcuts

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