lrand

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: MIT Imports: 1 Imported by: 1

README

lrand

Introdution

lrand based on Mersenne Twister algorithm. The Mersenne Twister is a strong pseudo-random number generator. Strong PRNG has a long period (how many values it generates before repeating itself) and a statistically uniform distribution of values (bits 0 and 1 are equally likely to appear regardless of previous values). A version of the Mersenne Twister available in many programming languages, MT19937, has an impressive period of 2^19937-1.

Installation

go get "github.com/belfinor/lrand"

Usage

There are two options for using the library: global context or custom context.

Custom context
package main

import (

  "fmt"
  "time"

  "github.com/belfinor/lrand"
)

func main() {

  gen := lrand.New()
  gen.Seed(time.Now().UnixNano())


  for i := 0 ; i < 1000 ; i++ {

    // get int64 value
    // or you can call gen.Uint64 to get uint64
    fmt.Println(gen.Int63())
  }
}
Global context
package main

import (

  "fmt"

  "github.com/belfinor/lrand"
)

func main() {

  for i := 0 ; i < 1000 ; i++ {
    fmt.Println(lrand.Next()) // return int64
  }
}

In this case calls New/Seed are transparent to the developer. Moreover, in this case, the values ​​are precomputed and stored in the channel for optimization.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GlobalReseed int
)

Functions

func Next

func Next() int64

Types

type Mersenne

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

func New

func New() *Mersenne

func (*Mersenne) Int63

func (mt *Mersenne) Int63() int64

func (*Mersenne) Read

func (mt *Mersenne) Read(p []byte) (n int, err error)

func (*Mersenne) Seed

func (mt *Mersenne) Seed(seed int64)

func (*Mersenne) SeedFromSlice

func (mt *Mersenne) SeedFromSlice(key []uint64)

func (*Mersenne) Uint64

func (mt *Mersenne) Uint64() uint64

Jump to

Keyboard shortcuts

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