fork download
  1. package main
  2.  
  3. import (
  4. "bufio"
  5. "fmt"
  6. "math/rand"
  7. "os"
  8. "time"
  9. )
  10.  
  11. func main() {
  12.  
  13. users := make(map[int]string)
  14.  
  15. users[0] = "Mike"
  16. users[1] = "Paul"
  17. users[2] = "Steve"
  18. users[3] = "Lawrence"
  19. users[4] = "Stephen"
  20. users[5] = "James"
  21.  
  22. getNextSpeaker(users)
  23.  
  24. }
  25.  
  26. func getNextSpeaker(users map[int]string) {
  27. numUsers := len(users)
  28. list := randList(1, numUsers)
  29.  
  30. for _, element := range list {
  31. fmt.Println(users[element-1])
  32. pressAnyKey()
  33. }
  34.  
  35. }
  36.  
  37. func randList(min, max int) []int {
  38. if max < min {
  39. min, max = max, min
  40. }
  41. length := max - min + 1
  42. t0 := time.Now()
  43. rand.Seed(int64(t0.Nanosecond()))
  44. list := rand.Perm(length)
  45. for index, _ := range list {
  46. list[index] += min
  47. }
  48.  
  49. return list
  50. }
  51.  
  52. func pressAnyKey() string {
  53. fmt.Println("Press Return To Continue...")
  54. reader := bufio.NewReader(os.Stdin)
  55. input, err := reader.ReadString('\n')
  56. if err != nil {
  57. panic(err)
  58. }
  59.  
  60. return input
  61. }
Runtime error #stdin #stdout #stderr 0s 420480KB
stdin


stdout
Paul
Press Return To Continue...
Steve
Press Return To Continue...
stderr
panic: EOF

goroutine 1 [running]:
main.pressAnyKey(0xb784bf98, 0x1)
	/home/yDGuzY/prog.go:57 +0xf4
main.getNextSpeaker(0xb302220, 0xb302220)
	/home/yDGuzY/prog.go:32 +0x101
main.main()
	/home/yDGuzY/prog.go:22 +0x13c

goroutine 2 [syscall]:
created by runtime.main
	/usr/local/go/src/pkg/runtime/proc.c:221