File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed
Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -5,25 +5,24 @@ import (
55 "io/ioutil"
66 "math/rand"
77 "os"
8- "path"
98 "strings"
9+ "time"
1010
1111 "github.com/shilangyu/typer-go/settings"
12- "github.com/shilangyu/typer-go/utils"
1312)
1413
1514// ChooseText randomly chooses a text from the dataset
1615func ChooseText () (string , error ) {
1716 if _ , err := os .Stat (settings .I .TextsPath ); os .IsNotExist (err ) {
1817 return "" , errors .New ("Didnt find typer texts, make sure your path is correct" )
1918 }
19+ rand .Seed (time .Now ().UTC ().UnixNano ())
2020
21- bytes , err := ioutil .ReadFile (path . Join ( utils . Root (), "texts.txt" ) )
21+ bytes , err := ioutil .ReadFile (settings . I . TextsPath )
2222 if err != nil {
23- return "" , nil
23+ return "" , errors . New ( "Couldnt load the typer texts, make sure the permission are correct" )
2424 }
25- content := string (bytes )
26- texts := strings .Split (content , "\n " )
25+ texts := strings .Split (string (bytes ), "\n " )
2726 texts = texts [:len (texts )- 1 ]
2827
2928 return texts [rand .Intn (len (texts ))], nil
You can’t perform that action at this time.
0 commit comments