rand

package
v3.0.0-...-66753ca Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package rand implements cancelable reads from a cryptographically safe random number source.

Index

Constants

This section is empty.

Variables

Reader is a cryptographically safe random number source.

Functions

func Read

func Read(b []byte) (int, error)

Read blockingly reads from a random number source.

func ReadContext

func ReadContext(ctx context.Context, b []byte) (int, error)

ReadContext is a context-aware reader for random numbers.

Types

type ContextReader

type ContextReader interface {
	// Read behaves like a blocking io.Reader.Read.
	//
	// Read wraps ReadContext with a background context.
	Read(b []byte) (n int, err error)

	// ReadContext is an io.Reader that blocks until data is available or
	// until ctx is done.
	ReadContext(ctx context.Context, b []byte) (n int, err error)
}

ContextReader is a cancelable io.Reader.

func DefaultReaderWithContext

func DefaultReaderWithContext(ctx context.Context) ContextReader

DefaultReaderWithContext returns a context-aware io.Reader.

Because this stores the context, only use this in situations where an io.Reader is unavoidable.

Jump to

Keyboard shortcuts

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