목록파일읽기 (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..
IT 인터넷/Golang
2022. 4. 29. 21:12