randx

package
v0.0.0-...-adcb032 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

README

randx

GoDoc

Package randx contains random-related utilities. It means to be a complement to the standard math/rand package.

Documentation

Overview

Package randx contains random-related utilities. It means to be a complement to the standard math/rand package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomIntWeight

func RandomIntWeight(weights ...int) int

RandomIntWeight chooses an index randomly using the listed non-negative relative weights.

The default Rand of math/rand package is used for random data.

Implementation guarantees to return an integer in the range of [0..len(weights)). If no weight is provided or they add up to 0, -1 is returned. Behavior for negative weights is undefined.

func RandomWeight

func RandomWeight(weights ...float64) int

RandomWeight chooses an index randomly using the listed (non-negative) probabilities as weights. Weights must add up to 1.

The default Rand of math/rand package is used for random data.

Implementation guarantees to return an integer in the range of [0..len(weights)). If weights don't add up to 1, -1 may be returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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