dice

package module
v0.0.0-...-47c6eec Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2016 License: MIT Imports: 2 Imported by: 0

README

dice

GoDocBuild Status

Dice is a package for die or dice generation. Specify the number of sides of a die; for more than one die, specify the dice quantity.

The dice roll is done using crypto/rand. There is a PCG based PRNG implementation under github.com/mohae/dice/quick. This is mostly for testability, but may be used if a CSPRNG isn't necessary for your use case.

An example program is in the dice/roll directory.

Usage

import "github.com/mohae/dice "

// die w 6 sides
d := dice.NewDie(6)

n, err := d.Roll()
if err != nil {
    // handle error
}
fmt.Println(n)

Roll

Roll is the example cli app. It accepts a -sides flag that tells it how many sides the die should have and an optional paramater that specifies how many rolls should be done.

If -sides isn't used, the die will default to 6 sides. If the number of rolls isn't passed, the die will only be rolled once. The number of rolls must be a valid number.

If you don't have the repo in your GOPATH:

go install github.com/mohae/dice/roll

Or in the roll directory:

go install

Run roll: roll 5

roll 3
4
1
5

roll -sides=20
14

Documentation

Overview

Package dice implements a die that uses crypto/rand for its roll.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Die

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

Die has n sides. Use New(n) to obtain a n-sided Die.

func New

func New(n int) Die

New returns a Die with n sides.

func (Die) Roll

func (d Die) Roll() (int, error)

Roll rolls the die. It returns either the roll results or an error.

Directories

Path Synopsis
Package qdice provides non-CSPRNG dice.
Package qdice provides non-CSPRNG dice.
Package roll is an example CLI die app that rolls a die n times where n is a number passed to the application as an arg.
Package roll is an example CLI die app that rolls a die n times where n is a number passed to the application as an arg.

Jump to

Keyboard shortcuts

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