random

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package random should be used in preference to the math/rand package when a random number is required inside the emulation.

There are two functions belonging to the Rewind type that return random numbers:

Rewindable() returns numbers based on the current television coordinates. The number will always return the same number for the same coordinates. As such it is compatible with the emulator's rewind system.

NoRewind() returns random numbers regardless of the current television coordinates. It is therefore, not compatiable with the emulator's rewind system.

Parallel emulators should return the same sequence of random numbers even if NoRewind() is used.

If the same random numbers are required every single time then set ZeroSeed to true. This is useful for testing purposes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Random

type Random struct {

	// use zero seed rather than the random base seed. this is only really
	// useful for normalised instances where random numbers must be predictable
	ZeroSeed bool
	// contains filtered or unexported fields
}

Random is a random number generator that is sensitive to time within the emulation. Required for the rewind package and parallel emulations.

func NewRandom

func NewRandom(tv TV) *Random

NewRandom is the preferred method of initialisation for the Random type.

func (*Random) NoRewind

func (rnd *Random) NoRewind(n int) int

NoRewind uses the standard Go library for generating random numbers. It can be used to generate random numbers on a non-running emulation but it is not therefore compatible with the rewind system.

It is useful for generating a random state on startup.

The returned number will between zero and value given in the n parameter.

func (*Random) Rewindable

func (rnd *Random) Rewindable(n int) int

Rewindable generates a random number very quickly and based on the current television coordinates. It's only really suitable for use in a running emulation.

It does however have the property of being predictable during a sesssion and so is compatible with the rewind system.

The returned number will between zero and value given in the n parameter.

type TV

type TV interface {
	GetCoords() coords.TelevisionCoords
}

TV defines the television functions required by the Random type.

Jump to

Keyboard shortcuts

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