updates
This commit is contained in:
parent
1c1430e3b8
commit
c47025edf6
35 changed files with 287 additions and 186 deletions
|
|
@ -1,5 +1,15 @@
|
|||
package sequence
|
||||
|
||||
// Values returns the array values of a linear sequence with a given start, end and optional step.
|
||||
func Values(start, end float64) []float64 {
|
||||
return Seq{NewLinear().WithOffset(start).WithLimit(end).WithStep(1.0)}.Array()
|
||||
}
|
||||
|
||||
// ValuesWithStep returns the array values of a linear sequence with a given start, end and optional step.
|
||||
func ValuesWithStep(start, end, step float64) []float64 {
|
||||
return Seq{NewLinear().WithOffset(start).WithLimit(end).WithStep(step)}.Array()
|
||||
}
|
||||
|
||||
// NewLinear returns a new linear generator.
|
||||
func NewLinear() *Linear {
|
||||
return &Linear{}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,26 @@ package sequence
|
|||
import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RandomValues returns an array of random values.
|
||||
func RandomValues(count int) []float64 {
|
||||
return Seq{NewRandom().WithLen(count)}.Array()
|
||||
}
|
||||
|
||||
// RandomValuesWithAverage returns an array of random values with a given average.
|
||||
func RandomValuesWithAverage(average float64, count int) []float64 {
|
||||
return Seq{NewRandom().WithAverage(average).WithLen(count)}.Array()
|
||||
}
|
||||
|
||||
// NewRandom creates a new random sequence.
|
||||
func NewRandom() *Random {
|
||||
return &Random{
|
||||
rnd: rand.New(rand.NewSource(time.Now().Unix())),
|
||||
}
|
||||
}
|
||||
|
||||
// Random is a random number sequence generator.
|
||||
type Random struct {
|
||||
rnd *rand.Rand
|
||||
|
|
|
|||
|
|
@ -13,6 +13,15 @@ type Seq struct {
|
|||
Provider
|
||||
}
|
||||
|
||||
// Array enumerates the sequence into a slice.
|
||||
func (s Seq) Array() (output []float64) {
|
||||
output = make([]float64, s.Len())
|
||||
for i := 0; i < s.Len(); i++ {
|
||||
output[i] = s.GetValue(i)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Each applies the `mapfn` to all values in the value provider.
|
||||
func (s Seq) Each(mapfn func(int, float64)) {
|
||||
for i := 0; i < s.Len(); i++ {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue