math/rand

This commit is contained in:
David Eisinger
2023-07-16 22:12:21 -04:00
parent 29c6d8b3e4
commit e21e901ef0

View File

@@ -132,6 +132,10 @@ I find [Go][1] really compelling, even though it's not super applicable to my jo
* Go has anonymous functions (`func` w/o name) * Go has anonymous functions (`func` w/o name)
* Slices * Slices
* Use `append` to add to a slice; this creates a new slice, so you have to capture the return value (`s = append(s, 100)`) * Use `append` to add to a slice; this creates a new slice, so you have to capture the return value (`s = append(s, 100)`)
* `math/rand`
* `rand.Intn`: random integer between 0 and the specified int
* `rand.Float64`: random float between 0.0. and 1.0
* `rand.Shuffle`: randomize an array/slice; takes a length and a swap function
[17]: https://stackoverflow.com/a/40951013 [17]: https://stackoverflow.com/a/40951013
[18]: https://go.dev/doc/effective_go#named-results [18]: https://go.dev/doc/effective_go#named-results