This commit is contained in:
Sangeeth Sudheer 2024-05-02 18:15:18 +05:30
parent 7f782f3b1e
commit f8e2fedbd2
Signed by: x
GPG Key ID: F6D06ECE734C57D1
2 changed files with 31 additions and 2 deletions

View File

@ -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
View 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))
}