High-performance Rand library, far more efficient than the official library. Especially when concurrent.
To install this package, you need to install Go and set your Go workspace first.
- You first need Go installed, then you can use the below Go command to install superand.
go get -u github.com/LgoLgo/superand
- Import it in your code:
import "github.com/LgoLgo/superand"
It's a simple guessing game.
package main
import (
"fmt"
"github.com/LgoLgo/superand"
)
func main() {
maxNum := 100
rand := superand.New()
secretNumber := rand.Intn(maxNum)
// fmt.Println("The secret number is ", secretNumber)
fmt.Println("Please input your guess")
for {
var guess int
_, err := fmt.Scanf("%d", &guess)
if err != nil {
fmt.Println("Invalid input. Please enter an integer value")
continue
}
fmt.Println("You guess is", guess)
if guess > secretNumber {
fmt.Println("Your guess is bigger than the secret number. Please try again")
} else if guess < secretNumber {
fmt.Println("Your guess is smaller than the secret number. Please try again")
} else {
fmt.Println("Correct, you Legend!")
break
}
}
}
BenchmarkStandardRand
BenchmarkStandardRand-8 79792984 14.71 ns/op
Benchmarksuperand
Benchmarksuperand-8 54015529 20.42 ns/op
BenchmarkUnsafesuperand
BenchmarkUnsafesuperand-8 275500960 4.288 ns/op
BenchmarkStandardRandWithConcurrent
BenchmarkStandardRandWithConcurrent-8 13186624 91.46 ns/op
BenchmarksuperandWithConcurrent
BenchmarksuperandWithConcurrent-8 309059797 3.238 ns/op
This project is under the Apache License 2.0. See the LICENSE file for the full license text.