Commit dab4af4
Changed files (1)
serverHandlers.go
@@ -19,6 +19,22 @@ import (
var userTests map[string][]ClientTest
var userTestsLock = sync.RWMutex{}
+// randomizeArray takes an array and returns the shuffled version
+// following the Fisher-Yates shuffle
+func randomizeArray(array []Record) []Record {
+ var tempRecord Record
+ maxIndex := len(array)
+ currentIndex := maxIndex
+ for currentIndex != 0 {
+ randomIndex := rand.Intn(currentIndex)
+ currentIndex -= 1
+ tempRecord = array[currentIndex]
+ array[currentIndex] = array[randomIndex]
+ array[randomIndex] = tempRecord
+ }
+ return array
+}
+
// buildRecordArray builds an array of Records based on the parameter criteria
func buildRecordArray(numQuestions int, selectedCategories []string) ([]Record, error) {
recordArray := []Record{}