728x90 반응형 SMALL 파일읽기1 [Golang] 텍스트 파일 읽고 랜덤 아이템 추출하기 list.txt 김씨 이씨 박씨 강씨 최씨 송씨 홍씨 main.go package main import ( "bufio" "fmt" "math/rand" "os" "time" ) func main() { file, _ := os.Open("list.txt") defer file.Close() result := make([]string, 0) scanner := bufio.NewScanner(file) for scanner.Scan() { result = append(result, scanner.Text()) } rand.Seed(time.Now().UnixNano()) for i := 0; i < 3; i++ { rnd := rand.Intn(len(result)) fmt.Println(result[rn.. 2022. 4. 29. 이전 1 다음 728x90 반응형 LIST