pcg64

package
v0.0.0-...-27647ab Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

The MIT License

PCG Random Number Generation for C.

Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The MIT License

PCG Random Number Generation for C.

Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The MIT License

PCG Random Number Generation for C.

Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mul128Parts

func Mul128Parts(x uint64, y uint64, z1 *uint64, z0 *uint64)

func Ror64

func Ror64(value uint64, rot uint) uint64

Types

type Rng

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

func (*Rng) Advance

func (rng *Rng) Advance(delta Uint128)

func (*Rng) BoundRand

func (rng *Rng) BoundRand(bound uint64) uint64

func (*Rng) CheapAdvance

func (rng *Rng) CheapAdvance(delta Uint128)

func (*Rng) CheapRand

func (rng *Rng) CheapRand() uint64

func (*Rng) CheapSeed

func (rng *Rng) CheapSeed(initState Uint128, initSeq Uint128)

func (*Rng) CheapStep

func (rng *Rng) CheapStep()

func (*Rng) Rand

func (rng *Rng) Rand() uint64

func (*Rng) Seed

func (rng *Rng) Seed(initState Uint128, initSeq Uint128)

func (*Rng) Step

func (rng *Rng) Step()

type State

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

func New

func New() *State

func (*State) Advance

func (st *State) Advance(step []uint64)

func (*State) CheapAdvance

func (st *State) CheapAdvance(step []uint64)

func (*State) CheapNext32

func (st *State) CheapNext32() uint32

func (*State) CheapNext64

func (st *State) CheapNext64() uint64

func (*State) GetState

func (st *State) GetState(state []uint64, hasUi *int, ui *uint32)

func (*State) Next32

func (st *State) Next32() uint32

func (*State) Next64

func (st *State) Next64() uint64

func (*State) Seed

func (st *State) Seed(seed []uint64, inc []uint64)

func (*State) SetState

func (st *State) SetState(state []uint64, hasUi int, ui uint32)

type Uint128

type Uint128 struct {
	High uint64
	Low  uint64
}

func Add128

func Add128(a Uint128, b Uint128) Uint128

func AdvanceLcg128

func AdvanceLcg128(state Uint128, delta Uint128, cur_mul Uint128, cur_plus Uint128) Uint128

Muli-step advance functions (jump-ahead, jump-back)

The method used here is based on Brown, "Random Number Generation with Arbitrary Stride,", Transactions of the American Nuclear Society (Nov. 1994). The algorithm is very similar to fast exponentiation.

Even though delta is an unsigned integer, we can pass a signed integer to go backwards, it just goes "the long way round".

func Mul128

func Mul128(a Uint128, b Uint128) Uint128

func Mul128Low

func Mul128Low(a Uint128, b uint64) Uint128

func (Uint128) String

func (v Uint128) String() string

Jump to

Keyboard shortcuts

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