rand

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Const

func Const(seed ...int) func() float64

Const returns a constant number in [0.0, 1.0).

Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/rand"
)

func main() {
	c := rand.Const()
	fmt.Printf("%.13f\n", c())
	fmt.Printf("%.13f\n", c())
	fmt.Printf("%.13f\n", c())
	fmt.Printf("%.13f\n", rand.Const(1)())
	fmt.Printf("%.13f\n", rand.Const(1)())
	fmt.Printf("%.13f\n", rand.Const(1)())
	fmt.Printf("%.13f\n", rand.Const(2)())
	fmt.Printf("%.13f\n", rand.Const(3)())

}
Output:

0.6046602879796
0.9405090880450
0.6645600532185
0.6046602879796
0.6046602879796
0.6046602879796
0.1672966344259
0.7199826688373

func Coprime

func Coprime(N int) int

Coprime returns a random coprime number in [2, N).

Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/rand"
)

func main() {
	p := rand.Coprime(15)

	for _, e := range []int{2, 4, 7, 8, 11, 13, 14} {
		if p == e {
			fmt.Println("found")
			break
		}
	}

}
Output:

found

func Crypto

func Crypto() func() float64

Crypto returns a random float64 in [0, 1).

func CryptoInt64

func CryptoInt64(min, max int64) int64

CryptoInt64 returns a random int64 in [min, max).

Example
package main

import (
	"fmt"

	"github.com/itsubaki/q/math/rand"
)

func main() {
	r := rand.CryptoInt64(2, 14)

	for _, e := range []int64{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13} {
		if r == e {
			fmt.Println("found")
			break
		}
	}

}
Output:

found

func Math added in v0.0.2

func Math() func() float64

Types

This section is empty.

Jump to

Keyboard shortcuts

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