seed

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package seed provides seeds used to decide behavior during query generation.

For example, a clause may decide to return a value if the seed returns an even value. Else it decides to returns no value.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Seed

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

A Seed has the GetByte function, which can be used by clauses to guide generation.

func GetPregeneratedByteString

func GetPregeneratedByteString(byteString []byte) *Seed

GetPregeneratedByteString returns a seed which returns the bytes passed in the slice of bytes in order. If the passed slice is too short, it starts randomly generating future bytes after exhausting the slice of bytes.

Example

Test that the pregenerated byte string returns the passed bytes in order

package main

import (
	"fmt"

	"github.com/Anon10214/dinkel/seed"
)

func main() {
	byteString := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	seed := seed.GetPregeneratedByteString(byteString)

	for range byteString {
		fmt.Printf("%d ", seed.GetByte())
	}
}
Output:

0 1 2 3 4 5 6 7 8 9

func GetRandomByteString

func GetRandomByteString() *Seed

GetRandomByteString returns a seed returning randomly generated bytes.

func GetRandomByteStringWithSource

func GetRandomByteStringWithSource(source rand.Rand) *Seed

GetRandomByteStringWithSource returns a seed returning bytes which get read from the passed source.

func (*Seed) BooleanWithProbability

func (s *Seed) BooleanWithProbability(probability float64) bool

BooleanWithProbability uses the passed seed to generate a boolean with the value "true" with the probability provided. Assumes that 0 <= probability <= 1

func (*Seed) GetByte

func (s *Seed) GetByte() byte

GetByte returns the next byte of the seed's underlying source

func (*Seed) GetByteString

func (s *Seed) GetByteString() []byte

GetByteString returns the string of bytes which have been generated

func (*Seed) GetRandomInt64

func (s *Seed) GetRandomInt64() int64

GetRandomInt64 returns a random int64 generated with the seed

func (*Seed) GetRandomIntn

func (s *Seed) GetRandomIntn(n int) int

GetRandomIntn returns a random int in [0, n)

func (*Seed) GetRandomPositiveInt64

func (s *Seed) GetRandomPositiveInt64() int64

GetRandomPositiveInt64 returns a random positive int64 generated with the seed

func (*Seed) RandomBoolean

func (s *Seed) RandomBoolean() bool

RandomBoolean returns true with probability 0.5, else false

func (*Seed) RandomStringFromChoice

func (s *Seed) RandomStringFromChoice(choice ...string) string

RandomStringFromChoice takes in an arbitrary amount of strings and returns one of them randomly.

Jump to

Keyboard shortcuts

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