Add rand
This commit is contained in:
parent
7f782f3b1e
commit
f8e2fedbd2
6
main.go
6
main.go
@ -28,7 +28,8 @@ package main
|
|||||||
// import "git.sangeeth.dev/gobyexample/regex"
|
// import "git.sangeeth.dev/gobyexample/regex"
|
||||||
// import "git.sangeeth.dev/gobyexample/json"
|
// import "git.sangeeth.dev/gobyexample/json"
|
||||||
// import "git.sangeeth.dev/gobyexample/xml"
|
// import "git.sangeeth.dev/gobyexample/xml"
|
||||||
import "git.sangeeth.dev/gobyexample/time"
|
// import "git.sangeeth.dev/gobyexample/time"
|
||||||
|
import "git.sangeeth.dev/gobyexample/rand"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// runes.Runes()
|
// runes.Runes()
|
||||||
@ -59,5 +60,6 @@ func main() {
|
|||||||
// regex.Regex()
|
// regex.Regex()
|
||||||
// json.Json()
|
// json.Json()
|
||||||
// xml.Xml()
|
// xml.Xml()
|
||||||
time.Time()
|
// time.Time()
|
||||||
|
rand.Rand()
|
||||||
}
|
}
|
||||||
|
27
rand/rand.go
Normal file
27
rand/rand.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package rand
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand/v2"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Rand() {
|
||||||
|
dur := rand.N(5 * time.Second)
|
||||||
|
fmt.Println(dur)
|
||||||
|
|
||||||
|
fmt.Println("Ints")
|
||||||
|
fmt.Print(rand.IntN(5), " ")
|
||||||
|
fmt.Print(rand.IntN(5), " ")
|
||||||
|
fmt.Print(rand.IntN(5), " ")
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
fmt.Println("Floats")
|
||||||
|
fmt.Println(rand.Float64())
|
||||||
|
fmt.Println("b/w 5 and 10:", rand.Float64()*5+5)
|
||||||
|
|
||||||
|
fmt.Println("Custom seed")
|
||||||
|
pcg := rand.NewPCG(1024, 10)
|
||||||
|
myRand := rand.New(pcg)
|
||||||
|
fmt.Printf("%d %d %d\n", myRand.IntN(5), myRand.IntN(5), myRand.IntN(5))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user