gorn

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 2 Imported by: 0

README

gorn — Go Random Numbers

A simple Go library for generating slices of random float64 values within configurable bounds.

Installation

go get github.com/bigohk/gorn

Requires Go 1.22 or later.

Usage

package main

import (
    "fmt"
    "github.com/bigohk/gorn"
)

func main() {
    // Generate 5 random numbers between 0 and 100 (defaults)
    nums, err := gorn.GenerateRandoms(5)
    if err != nil {
        panic(err)
    }
    fmt.Println(nums)

    // Generate 3 random numbers between 10 and 50
    nums, err = gorn.GenerateRandoms(3,
        gorn.WithLowerBound(10),
        gorn.WithUpperBound(50),
    )
    if err != nil {
        panic(err)
    }
    fmt.Println(nums)
}

API Reference

GenerateRandoms
func GenerateRandoms(numOutputRnds int, opts ...Option) ([]float64, error)

Returns a slice of numOutputRnds random float64 values in the range [lower, upper).

Parameters:

Parameter Type Description
numOutputRnds int Number of random values to generate. Must be > 0.
opts ...Option Optional functional options to configure bounds.

Errors:

  • "numOutputRnds must be greater than 0" — when numOutputRnds <= 0
  • "lower bound must be less than upper bound" — when lower >= upper
Options
WithLowerBound
func WithLowerBound(lower float64) Option

Sets the lower bound (inclusive) for generated values. Default: 0.

WithUpperBound
func WithUpperBound(upper float64) Option

Sets the upper bound (exclusive) for generated values. Default: 100.

License

MIT

Documentation

Overview

Package gorn (Go Random Numbers) provides a simple function for generating slices of random float64 values within configurable bounds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandoms

func GenerateRandoms(numOutputRnds int, opts ...Option) ([]float64, error)

GenerateRandoms returns a slice of numOutputRnds random float64 values in the range [lower, upper). By default, lower is 0 and upper is 100.

Use WithLowerBound and WithUpperBound to customise the range.

Returns an error if numOutputRnds <= 0 or if lower >= upper.

Types

type Option

type Option func(*config)

Option is a functional option for configuring GenerateRandoms.

func WithLowerBound

func WithLowerBound(lower float64) Option

WithLowerBound sets the lower bound (inclusive) for generated random numbers. The default lower bound is 0.

func WithUpperBound

func WithUpperBound(upper float64) Option

WithUpperBound sets the upper bound (exclusive) for generated random numbers. The default upper bound is 100.

Jump to

Keyboard shortcuts

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