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
+15.5k Golang : Find location by IP address and display with Google Map
+20.7k Golang : Saving private and public key to files
+7.9k Golang : Get today's weekday name and calculate target day distance example
+7.5k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+43.4k Golang : Convert []byte to image
+4.9k Unix/Linux : secure copying between servers with SCP command examples
+5.2k Golang : Customize scanner.Scanner to treat dash as part of identifier
+14.6k Golang : How to get URL port?
+14.5k Golang : How to pass map to html template and access the map's elements
+16.6k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+9.4k Golang : Generate EAN barcode
+9.8k Golang : Detect number of active displays and the display's resolution