Help us shape the future of Go! Take the 2026 Go Developer Survey

xorshift

package module
v0.0.0-...-ce511d4 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2017 License: MIT Imports: 0 Imported by: 9

README

xorshift Build Status

A golang implementation of the xorshift family of pseudorandom number generators.

These generators are simultaneously high quality, fast, cache-line friendly, simple to implement, have a large period and pass the TestU01 statistical tests.

xorshift1024* and xorshift128+ seem to be strictly better than the Mersenne Twister and WELL family of PRNGs in every dimension. For more details, see the xorshift webpage.

References

Example

  package main

  import (
    "fmt"
    "time"  
    "github.com/lazybeaver/xorshift"
  )

  func main() {
    seed := uint64(time.Now().Nanosecond())

    xor64s := xorshift.NewXorShift64Star(seed)
    fmt.Printf("xorshift64*    : %x\n", xor64s.Next())

    xor128p := xorshift.NewXorShift128Plus(seed)
    fmt.Printf("xorshift128+   : %x\n", xor128p.Next())

    xor1024s := xorshift.NewXorShift1024Star(seed)
    fmt.Printf("xorshift1024s  : %x\n", xor1024s.Next())
  }

Benchmarks

  $ go test -bench=.
  PASS
  BenchmarkXorShift1024Star	500000000	         7.20 ns/op
  BenchmarkXorShift128Plus	500000000	         3.83 ns/op
  BenchmarkXorShift64Star	500000000	         6.83 ns/op
  ok  	github.com/lazybeaver/xorshift	10.748s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type XorShift

type XorShift interface {
	Next() uint64
}

A generic xorshift PRNG interface

func NewXorShift64Star

func NewXorShift64Star(seed uint64) XorShift

Return a xorshift64* generator with a period of 2^64 - 1 Use this only as a seed generator for other PRNGs Reference: http://vigna.di.unimi.it/ftp/papers/xorshift.pdf

func NewXorShift128Plus

func NewXorShift128Plus(seed uint64) XorShift

Return a xorshift128+ generator with a period of 2^128 - 1 Reference: http://vigna.di.unimi.it/ftp/papers/xorshiftplus.pdf

func NewXorShift1024Star

func NewXorShift1024Star(seed uint64) XorShift

Return a xorshift1024* generator with a period of 2^1024 - 1 Reference: http://vigna.di.unimi.it/ftp/papers/xorshift.pdf

type XorShift64Star

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

func (*XorShift64Star) Next

func (x *XorShift64Star) Next() uint64

type XorShift128Plus

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

func (*XorShift128Plus) Next

func (x *XorShift128Plus) Next() uint64

type XorShift1024Star

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

func (*XorShift1024Star) Next

func (x *XorShift1024Star) Next() uint64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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