rand

package
v0.0.0-...-885409b Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Const

func Const(seed ...uint64) randv2.Source

Const returns a source of constant pseudo-random number generator

Example
package main

import (
	"fmt"
	randv2 "math/rand/v2"

	"github.com/itsubaki/neu/math/rand"
)

func main() {
	s := rand.Const()
	fmt.Printf("%.13f\n", randv2.New(s).Float64())
	fmt.Printf("%.13f\n", randv2.New(s).Float64())
	fmt.Printf("%.13f\n", randv2.New(rand.Const(1)).Float64())
	fmt.Printf("%.13f\n", randv2.New(rand.Const(1)).Float64())
	fmt.Printf("%.13f\n", randv2.New(rand.Const(1)).Float64())
	fmt.Printf("%.13f\n", randv2.New(rand.Const(2)).Float64())
	fmt.Printf("%.13f\n", randv2.New(rand.Const(3)).Float64())
	fmt.Printf("%.13f\n", randv2.New(rand.Const(1, 0)).Float64())
	fmt.Printf("%.13f\n", randv2.New(rand.Const(1, 1)).Float64())
	fmt.Printf("%.13f\n", randv2.New(rand.Const(1, 2)).Float64())

}
Output:

0.9999275824803
0.8856419373529
0.2384231908739
0.2384231908739
0.2384231908739
0.8269781200925
0.8353847703964
0.2384231908739
0.3402859786606
0.6764556596678

func Must

func Must[T any](a T, err error) T

func MustRead

func MustRead() [32]byte

func NewSource

func NewSource(seed [32]byte) randv2.Source

NewSource returns a source of pseudo-random number generator

func Read

func Read() ([32]byte, error)
Example
package main

import (
	crand "crypto/rand"
	"fmt"
	"strings"

	"github.com/itsubaki/neu/math/rand"
)

func main() {
	reader := crand.Reader
	defer func() {
		crand.Reader = reader
	}()

	crand.Reader = strings.NewReader("io.Reader stream to be read\n")
	if _, err := rand.Read(); err != nil {
		fmt.Println(err)
	}

}
Output:

read: unexpected EOF

Types

This section is empty.

Jump to

Keyboard shortcuts

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