about summary refs log tree commit diff
path: root/csv
diff options
context:
space:
mode:
authoremile <hanemile@protonmail.com>2018-10-15 13:07:06 +0200
committeremile <hanemile@protonmail.com>2018-10-15 13:07:06 +0200
commitabf9f1ec491894cc5a68a84ae96f0166dbeb3290 (patch)
tree2b25d3dba075b8f7b2491c40481c4cb0784c74cf /csv
parentb9700e6860cddabc0c3e0d85344863fc7057af36 (diff)
Set the mass of the stars to a random number in the range [1e4;1e5]
Diffstat (limited to 'csv')
-rw-r--r--csv/csv.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/csv/csv.go b/csv/csv.go
index dc4cdf1..5e682a7 100644
--- a/csv/csv.go
+++ b/csv/csv.go
@@ -4,8 +4,10 @@ import (
 	"../structs"
 	"encoding/csv"
 	"log"
+	"math/rand"
 	"os"
 	"strconv"
+	"time"
 )
 
 // openStarCSV opens the file at the given path and reads its content. It then returns the content inform of a slice
@@ -40,6 +42,10 @@ func openStarCSV(path string) [][]string {
 func Import(path string, start int, end int, slice []structs.Star) []structs.Star {
 	lines := openStarCSV(path)
 
+	// seed the random number generator
+	rand.Seed(time.Now().UTC().UnixNano())
+
+	// iterate over all the lines in the given range
 	for linenr, line := range lines[start:end] {
 		x, errx := strconv.ParseFloat(line[0], 64)
 		y, erry := strconv.ParseFloat(line[1], 64)
@@ -56,11 +62,14 @@ func Import(path string, start int, end int, slice []structs.Star) []structs.Sta
 			log.Printf("error reading value from csv in line nr. %d (%s)", linenr, errz)
 		}
 
+		// TODO: Export the code below to its own function
+		var mass float64 = float64(10000 + rand.Intn(100000-10000))
+
 		// Create a temporary star for assembling the star
 		tempStar := structs.Star{
 			structs.Coord{X: x, Y: y, Z: z},
 			structs.Force{X: 0, Y: 0, Z: 0},
-			50000,
+			mass,
 		}
 
 		// Add the Temporary star to the slice