<commit_before>package main

import (
	"io/ioutil"
	"strings"
	"time"
)

type Game struct {
	wordList  []string  // Slice of words to practice
	curStats  Stats     // Stats for current session
	stats     Stats     // Stats for current session + all past sessions
	curWord   int       // Index of current word in wordList
	curChar   int       // Index of current char of current word
	startTime time.Time // Start time of current session
}

func (g *Game) loadWords(filename string) bool {
	words, err := ioutil.ReadFile(filename)
	if err != nil {
		return false
	}
	g.wordList = strings.Split(string(words), "\n")
	return true
}

func (g *Game) loadStats(filename string) bool {
	return g.stats.loadStats(filename)
}

func (g *Game) initTime() {
	g.startTime = time.Now()
}

func (g *Game) gameTime() float64 {
	return time.Since(g.startTime).Seconds()
}

func NewGame(wordsFile string, statsFile string) *Game {
	g := new(Game)
	if !g.loadWords(wordsFile) {
		panic("Failed to load wordsFile: \"" + wordsFile + "\"")
	}
	if !g.loadStats(statsFile) {
		panic("Failed to load statsFile: \"" + statsFile + "\"")
	}
	return g
}<commit_msg>Randomize word order<commit_after>package main

import (
	"io/ioutil"
	"math/rand"
	"strings"
	"time"
)

func shuffle(a []string) {
	for i := range a {
		j := rand.Intn(i + 1)
		a[i], a[j] = a[j], a[i]
	}
}

type Game struct {
	wordList  string    // String containing all words
	curChar   int       // Index of current char
	curStats  Stats     // Stats for current session
	stats     Stats     // Stats for current session + all past sessions
	startTime time.Time // Start time of current session
}

func (g *Game) loadWords(filename string) bool {
	rand.Seed(time.Now().UnixNano())

	words, err := ioutil.ReadFile(filename)
	if err != nil {
		return false
	}

	wordSlice := strings.Split(string(words), "\n")
	shuffle(wordSlice)

	g.wordList = strings.Join(wordSlice, " ")

	return true
}

func (g *Game) loadStats(filename string) bool {
	return g.stats.loadStats(filename)
}

func (g *Game) initTime() {
	g.startTime = time.Now()
}

func (g *Game) gameTime() float64 {
	return time.Since(g.startTime).Seconds()
}

func (g *Game) getRune(index int) rune {
	return rune(g.wordList[index])
}

func NewGame(wordsFile string, statsFile string) *Game {
	g := new(Game)
	if !g.loadWords(wordsFile) {
		panic("Failed to load wordsFile: \"" + wordsFile + "\"")
	}
	if !g.loadStats(statsFile) {
		panic("Failed to load statsFile: \"" + statsFile + "\"")
	}
	return g
}
{'fraction_non_alphanumeric': 0.13725490196078433, 'fraction_numerical': 0.0020008003201280513, 'mean_word_length': 3.488330341113106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4237189', 'n_tokens_mistral': 910, 'n_tokens_neox': 880, 'n_words': 255}