This is a creation in Article, where the information may have evolved or changed.
Original text sync to: http://www.waylau.com/golang-game-guess-numbe/
Randomly generate a number, enter a number to see if the pair, matching the junction speed, the opposite hint is big or small,
The code is as follows:
Package Mainimport ("Bufio" "FMT" "Math/rand" "OS" "StrConv" "Time") var (endnum int//Set the range of generated numbers) Func main () {i: = Createrandomnumber (Endnum)//fmt. PRINTLN ("Generates an integer within the specified range:", i) //This sentence is debugged with FMT. Println ("Please enter an integer, Range: 0-", endnum) Flag: = Truereader: = Bufio. Newreader (OS. Stdin) for flag {data, _, _: = Reader. ReadLine () command, err: = StrConv. Atoi (String)//string to int and makes an input format to determine if err! = Nil {fmt. PRINTLN ("Format is incorrect, enter a number")} else {fmt. Println ("You enter the number:", command) if command = = i {flag = falsefmt. Println ("Congratulations, right")} else if command < I {FMT. Println ("The number you entered is less than the number generated, don't be discouraged!") One more Time ~ ")} else if command > I {fmt. Println ("The number you entered is greater than the number generated, don't be discouraged!") One more Time ~ ")}}}}func init () {endnum = 10}//generates integers within the specified range//Set starting numeric range, 0 start, Endnum cutoff func createrandomnumber (endnum int) int {r: = Rand. New (Rand. Newsource (time. Now (). Unixnano ())) return R.intn (Endnum)}