diff --git a/create_db.go b/create_db.go index e41878f..c9e6e46 100644 --- a/create_db.go +++ b/create_db.go @@ -3,7 +3,9 @@ package main import ( "database/sql" "fmt" + "flag" "io/ioutil" + "math/rand" "log" "strings" @@ -22,8 +24,14 @@ var topEnglishWords = []string{ } func main() { + dbPtr := flag.String("db", "./english_words.db", "SQLite3 DB file to use") + flag.Parse() + + // Randomize high Freq. words + shuffleArray(topEnglishWords) + // Open SQLite database file - db, err := sql.Open("sqlite3", "./english_words.db") + db, err := sql.Open("sqlite3", *dbPtr) if err != nil { log.Fatal(err) } @@ -93,3 +101,14 @@ func main() { fmt.Println("American-English words inserted into the database.") } + +func shuffleArray(arr []string) { + n := len(arr) + for i := n - 1; i > 0; i-- { + // Generate a random index between 0 and i (inclusive) + j := rand.Intn(i + 1) + + // Swap the elements at indices i and j + arr[i], arr[j] = arr[j], arr[i] + } +} diff --git a/readData.go b/readData.go index 6132b4a..20d0cdc 100644 --- a/readData.go +++ b/readData.go @@ -23,13 +23,14 @@ func containsSymbol(input string, symbols []string) bool { } func main() { - // Define a command-line flag for the filename + // Define a command-line flags + dbPtr := flag.String("db", "./english_words.db", "SQLite3 DB file to use") filenamePtr := flag.String("file", "results.txt", "Name of the file to write results to") pwdPtr := flag.String("pwd", "", "Enter a password") flag.Parse() // Open the SQLite3 database file - db, err := sql.Open("sqlite3", "./english_words.db") + db, err := sql.Open("sqlite3", *dbPtr) if err != nil { log.Fatal(err) } diff --git a/writeData.go b/writeData.go index e5e5483..24e522c 100644 --- a/writeData.go +++ b/writeData.go @@ -12,19 +12,15 @@ import ( _ "github.com/mattn/go-sqlite3" ) -var symbols = []string{ - ".", ",", "!", ";", "?", "(", ")", "'", "\"", -} - - func main() { - // Define a command-line flag for the filename + // Define a command-line flags + dbPtr := flag.String("db", "./english_words.db", "SQLite3 DB file to use") filenamePtr := flag.String("file", "results.txt", "Name of the file to write results to") pwdPtr := flag.String("pwd", "", "Enter a password") flag.Parse() // Open the SQLite3 database file - db, err := sql.Open("sqlite3", "./english_words.db") + db, err := sql.Open("sqlite3", *dbPtr) if err != nil { log.Fatal(err) }