I'm having difficulty creating a random value insert in Go, I need to do 10 tests with 1000 numbers, then 10 tests with 5000 numbers, then 10 tests with 10000 numbers, then 10 tests with 15000 ... up to 50000
I made a code with function and another code without function and the 2 are wrong
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
var vetor [50000]int
for k := 1; k <= 10; {
k := (5 ^ k) * 1000
for i := 1000; i < 50000; {
vetor[i] = rand.Intn(1000)
fmt.Print(vetor[i], ",")
}
start := time.Now()
n := len(vetor)
if n < 2 {
return
}
for i := 1; i < n; i++ {
for j := i - 1; j >= 0; j-- {
if (vetor)[j] > (vetor)[j+1] {
(vetor)[j], (vetor)[j+1] = (vetor)[j+1], (vetor)[j]
} else {
break
}
}
}
t := time.Now()
decorrido := t.Sub(start)
}
}
package main
import (
"fmt"
"math/rand"
"time"
)
func insertion(array *[]int) {
n := len(*array)
if n < 2 {
return
}
for i := 1; i < n; i++ {
for j := i - 1; j >= 0; j-- {
if (*array)[j] > (*array)[j+1] {
(*array)[j], (*array)[j+1] = (*array)[j+1], (*array)[j]
} else {
break
}
}
}
}
func main() {
var vetor [50000]int
for k := 1; k <= 10; {
k := (5 ^ k) * 1000
for i := 1000; i < 50000; {
vetor[i] = rand.Intn(1000)
fmt.Print(vetor[i], ",")
}
start := time.Now()
insertion(&vetor)
t := time.Now()
decorrido := t.Sub(start)
}
}
I also need to calculate the run time for all the tests and take the averages out of all 10 results