github.com/qiaogw/arrgo@v0.0.8/distrubution.go (about)

     1  package arrgo
     2  
     3  import (
     4  	"math/rand"
     5  	"time"
     6  )
     7  
     8  var (
     9  	r = rand.New(rand.NewSource(time.Now().UnixNano()))
    10  )
    11  
    12  func Seed(seed int64) {
    13  	r.Seed(seed)
    14  }
    15  
    16  //Return a random matrix with Data from the "standard normal" distribution.
    17  //
    18  //`randn` generates a matrix filled with random floats sampled from a
    19  //univariate "normal" (Gaussian) distribution of mean 0 and variance 1.
    20  //
    21  //Parameters
    22  //----------
    23  //\\*args : Arguments
    24  //Shape of the output.
    25  //If given as N integers, each integer specifies the size of one
    26  //dimension. If given as a tuple, this tuple gives the complete Shape.
    27  //
    28  //Returns
    29  //-------
    30  //Z : matrix of floats
    31  //A matrix of floating-point samples drawn from the standard normal
    32  //distribution.
    33  func Randn(Shape ...int) *Arrf {
    34  	a := Zeros(Shape...)
    35  	for i := range a.Values() {
    36  		a.Values()[i] = r.NormFloat64()
    37  	}
    38  
    39  	return a
    40  }