protorand

package
v0.12.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ProtoRand

type ProtoRand[T proto.Message] struct {
	*protorand.ProtoRand
	// contains filtered or unexported fields
}

func New

func New[T proto.Message]() *ProtoRand[T]

func (*ProtoRand[T]) ExcludeMask

func (p *ProtoRand[T]) ExcludeMask(mask *fieldmaskpb.FieldMask)

If non-nil, fields listed in the mask will be unset in generated messages. When generating a partial message, listed fields will not be included in the list of possible fields to select from, as if the fields did not exist in the message at all. Paths in the mask are relative to the root of the message and can include nested fields. If nested fields are listed, the mask only applies to "leaf" fields, and not to containing messages.

func (*ProtoRand[T]) Gen

func (p *ProtoRand[T]) Gen() (T, error)

func (*ProtoRand[T]) GenPartial

func (p *ProtoRand[T]) GenPartial(ratio float64) (T, error)

Generate a message with a specific ratio of set/unset fields.

If ratio is 0, the message will be empty. If it is 1, all fields will be set. Otherwise, a randomly chosen subset of fields will be set. The ratio of set fields to unset fields is given by min(1, round(ratio * size)) where size is the number of fields in the current message. This function applies recursively to all fields, using the original ratio.

This function reads the same amount of randomness from the underlying random number generator as a single call to Gen().

func (*ProtoRand[T]) MustGen

func (p *ProtoRand[T]) MustGen() T

func (*ProtoRand[T]) MustGenPartial

func (p *ProtoRand[T]) MustGenPartial(ratio float64) T

func (*ProtoRand[T]) Seed

func (p *ProtoRand[T]) Seed(seed int64)

Jump to

Keyboard shortcuts

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