Init
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
commit
bf11085207
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
go-overflow-sample
|
18
README.md
Normal file
18
README.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
```
|
||||||
|
$ go build
|
||||||
|
|
||||||
|
$ ./go-overflow-sample 999999999999999999
|
||||||
|
1492596583345867513
|
||||||
|
|
||||||
|
$ ./go-overflow-sample 9999999999999999999
|
||||||
|
Could not convert argument to int64
|
||||||
|
panic: crypto/rand: argument to Int is <= 0
|
||||||
|
|
||||||
|
goroutine 1 [running]:
|
||||||
|
crypto/rand.Int({0x4d0b88?, 0xc000014060?}, 0x0?)
|
||||||
|
/usr/lib64/go/1.22/src/crypto/rand/util.go:64 +0x2ca
|
||||||
|
main.RandInt(0x4d0b08?)
|
||||||
|
/home/georg/Work/git/go-overflow-sample/main.go:23 +0x86
|
||||||
|
main.main()
|
||||||
|
/home/georg/Work/git/go-overflow-sample/main.go:18 +0xdc
|
||||||
|
```
|
28
main.go
Normal file
28
main.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "crypto/rand"
|
||||||
|
import "math/big"
|
||||||
|
import "fmt"
|
||||||
|
import "os"
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) < 2 {
|
||||||
|
fmt.Println("Pass a number")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
number, err := strconv.Atoi(os.Args[1])
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Could not convert argument to int64")
|
||||||
|
}
|
||||||
|
RandInt(int64(number * 100))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func RandInt(max int64) {
|
||||||
|
i, err := rand.Int(rand.Reader, big.NewInt(int64(max)))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Could not randomize")
|
||||||
|
}
|
||||||
|
fmt.Println(i.Uint64())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user