dice

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2022 License: CC-BY-SA-4.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Die

type Die interface {
	// Roll rolls a new number.
	Roll() uint64

	// MaxValue returns the max number this die will ever roll,
	// inclusive.
	MaxValue() uint64

	// MinValue returns the min number this die will ever roll.
	MinValue() uint64
}

Die is the interface that provides the methods Roll, MaxValue, and MinValue. This package provides (private) implementors that are returned through the New* functions.

func New0Based

func New0Based(maxValue uint64) Die

New0Based returns a new die that will rolls numbers between 0 and `maxValue` exclusive. I.e., 0 <= die.Roll() < `maxValue`.

New0Based calls New0BasedWithSeed passing time.Now().UnixNano() as the seed.

func New0BasedWithSeed

func New0BasedWithSeed(maxValue uint64, seed int64) Die

New0BasedWithSeed returns a new die that will roll numbers between 0 and `maxValue` exclusive. I.e., 0 <= die.Roll() < `maxValue`.

The internal rand.Rand object will use `seed` as its seed.

func New1Based

func New1Based(maxValue uint64) Die

New1Based returns a new die that will rolls numbers between 1 and `maxValue` inclusive. I.e., 1 <= die.Roll() <= `maxValue`.

New1Based calls New1BasedWithSeed passing time.Now().UnixNano() as the seed.

func New1BasedWithSeed

func New1BasedWithSeed(maxValue uint64, seed int64) Die

New1BasedWithSeed returns a new die that will roll numbers between 1 and `maxValue` inclusive. I.e., 1 <= die.Roll() <= `maxValue`.

The internal rand.Rand object will use `seed` as its seed.

func NewLoaded

func NewLoaded(constantValue uint64) Die

NewLoaded returns a loaded die that always returns the same number, no matter how many times you roll it. Can be used to test code that uses dice, or to cheat in dice games.

Jump to

Keyboard shortcuts

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