Last active
August 25, 2021 12:04
Revisions
-
TrizlyBear revised this gist
Aug 25, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ package random import ( "math/rand" "reflect" -
TrizlyBear revised this gist
Aug 25, 2021 . No changes.There are no files selected for viewing
-
TrizlyBear created this gist
Aug 24, 2021 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ import ( "math/rand" "reflect" ) // Generate a multidimensional matrix with random numbers func Rand(seq ...int) interface{} { // Declare numbers to fill nums := seq[0] for _,el := range seq[1:] { nums *= el } // Generate the sequence of numbers left := []reflect.Value{} for i := 0; i < nums; i++ { left = append(left, reflect.ValueOf(rand.Float64())) } // Declare the type template t := reflect.TypeOf([]float64{}) // Reverse the sequence for i, j := 0, len(seq)-1; i < j; i, j = i+1, j-1 { seq[i], seq[j] = seq[j], seq[i] } // Loop over the sequence for _,a := range seq { n := []reflect.Value{} for y := 0; y < nums / a; y++ { holder := reflect.Zero(t) for i := 0; i < a; i++ { holder = reflect.Append(holder, left[0]) left = left[1:] } n = append(n, holder) } nums /= a left = n t = reflect.SliceOf(t) } return left[0].Interface() }