re: Write a simple but impactful script VIEW POST

FULL DISCUSSION
 

Here's my attempt using Go:
(Keep in mind that I've only been introduced to Go a few days ago so I have absolutely no idea what I'm doing, feel free to improve this)

package main

import(
  "bufio"
  "os"
  "fmt"
  "math/rand"
)

func main() {
  // generate and shuffle 0000 - 9999
  dest := make([]string, 10000)
  for i, v := range rand.Perm(10000) {
    dest[v] = fmt.Sprintf("%04d", i)
  }
  // write result to file
  f, _ := os.Create("result.txt")
  defer f.Close()
  w := bufio.NewWriter(f)
  for _, line := range dest {
    fmt.Fprintln(w, line)
  }
  w.Flush()
}

code of conduct - report abuse