Golang : Gonum standard normal random numbers example
Putting this simple example here for my own future reference. Just another way of generating random numbers beside using math/rand
.
In the code example below, we learn how to generate random numbers using the gonum.org/v1/gonum/stat/distuv
package.
Here you go!
package main
import (
"fmt"
"gonum.org/v1/gonum/stat/distuv"
)
func main() {
n := 1000 // number of simulations
// Create a standard normal (mean = 0, stdev = 1)
// https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.standard_normal.html
//dist := distuv.Normal{
// Mu: 0, // Mean of the normal distribution
// Sigma: 1, // Standard deviation of the normal distribution
//}
// use the defined variable
dist := distuv.UnitNormal.
z := make([]float64, n)
// Generate some random numbers from standard normal distribution
for i := range z {
z[i] = dist.Rand()
}
fmt.Println(z)
}
Reference :
See also : Golang : Create matrix with Gonum Matrix package example
By Adam Ng(黃武俊)
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+16.8k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+6.4k Linux/Unix : Commands that you need to be careful about
+12.6k Golang : Search and extract certain XML data example
+13.9k Golang : Activate web camera and broadcast out base64 encoded images
+18.5k Golang : Put UTF8 text on OpenCV video capture image frame
+8.9k Golang : How to join strings?
+5.3k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+10.8k Golang : Create matrix with Gonum Matrix package example
+14.6k Golang : Simple word wrap or line breaking example
+9.1k Golang : GMail API create and send draft with simple upload attachment example
+16k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+25.9k Golang : missing Mercurial command