tinymt32

package
v0.0.0-...-17533aa Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Source

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

Source is a random source using Tiny Mersenne Twister(TinyMT) algorithm.

Go port of https://github.com/MersenneTwister-Lab/TinyMT

func New

func New(mat1, mat2, tmat uint32, status [4]uint32) *Source

New creates a new source. mat1, mat2, and tmat are a parameter set that needs to be well chosen. the precalculated parameter sets are available at https://github.com/jj1bdx/tinymtdc-longbatch

func NewRFC8682

func NewRFC8682(seed uint32) *Source

NewRFC8682 creates new source that is defined by RFC8682. https://trac.tools.ietf.org/html/rfc8682

func (*Source) Int63

func (s *Source) Int63() int64

Int63 implements math/rand.Source.

func (*Source) Seed

func (s *Source) Seed(seed int64)

Seed implements math/rand.Source.

func (*Source) SeedBySlice

func (s *Source) SeedBySlice(initKey []uint32)

SeedBySlice initializes the state by initKey.

Example
package main

import (
	"fmt"

	"github.com/shogo82148/randsrc/tinymt32"
)

func main() {
	src := tinymt32.NewRFC8682(1)
	src.SeedBySlice([]uint32{1})
	for i := 0; i < 50; i++ {
		fmt.Println(src.Uint32())
	}
}
Output:
56890874
895028026
626205227
491377950
2651386131
224367844
4240771450
645612935
1734762751
2967542715
390009247
273717471
2148393711
453954016
402390906
261581451
311701506
3351172526
3763059905
2454325893
732916757
1737887887
1774344732
1213390409
3543090513
1795461913
924627520
1866661979
2111765104
2575882827
3916504541
828214179
3231223010
4247845528
3187523916
3888651459
1521484678
3934645087
519598026
3524224514
3690414521
3599140977
2851035974
3778034548
3697407623
3975036437
2781112304
3118216175
3761327779
363334073

func (*Source) Uint32

func (s *Source) Uint32() uint32

Uint32 returns pseudo-random uint32 values in the range [0, 1<<32).

Example
package main

import (
	"fmt"

	"github.com/shogo82148/randsrc/tinymt32"
)

func main() {
	src := tinymt32.NewRFC8682(1)
	for i := 0; i < 50; i++ {
		fmt.Println(src.Uint32())
	}
}
Output:
2545341989
981918433
3715302833
2387538352
3591001365
3820442102
2114400566
2196103051
2783359912
764534509
643179475
1822416315
881558334
4207026366
3690273640
3240535687
2921447122
3984931427
4092394160
44209675
2188315343
2908663843
1834519336
3774670961
3019990707
4065554902
1239765502
4035716197
3412127188
552822483
161364450
353727785
140085994
149132008
2547770827
4064042525
4078297538
2057335507
622384752
2041665899
2193913817
1080849512
33160901
662956935
642999063
3384709977
1723175122
3866752252
521822317
2292524454

func (*Source) Uint64

func (s *Source) Uint64() uint64

Uint64 implements math/rand.Source64

Jump to

Keyboard shortcuts

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