douketangyouzh5219
2017-05-17 13:50
浏览 561
已采纳

如何在Golang中随机播放数组中的字符串?

So I created a program to help me decide which game to play. Before I start my problem let me show you my code:

package main

import (
    "fmt"
    "strconv"
    "time"
)

func main() {
    isArray := [10]string{"Paladins", "Overwatch", "CS:GO", "Tanki", "Left 4 Dead", "Rocket League", "Call Of Duty : AW", "Portal", "Star Citizen", "Star Wars : Battlefront"}
    fmt.Print("0,1,2,3,4,5,6,7,8,9 := ")

    var (
        va string
        ar string
    )

    fmt.Scanln(&va)
    i, _ := strconv.Atoi(va)

    fmt.Print("You Should Play : ")
    fmt.Print(isArray[i], "
")
    fmt.Print("[Y/N] := ")
    fmt.Scanln(&ar)

    if ar != "N" || ar != "n" {
        fmt.Print("OK")
    }

    time.Sleep(3 * time.Second)
}

So the problems start when I already know which number would trigger a game, if I use it twice. So I am trying to make the strings random, like shuffling each time I use it, how can I do that?

3条回答 默认 最新

相关推荐 更多相似问题