Skip to content

Instantly share code, notes, and snippets.

@rustyrazorblade
Created June 16, 2013 23:18
Show Gist options
  • Save rustyrazorblade/5793810 to your computer and use it in GitHub Desktop.
Save rustyrazorblade/5793810 to your computer and use it in GitHub Desktop.
jon's I/O random binary writer in go
package main
import (
"fmt"
"math/rand"
"time"
"os"
"encoding/binary"
"bytes"
)
func main() {
fmt.Println("Hello world!")
t := time.Now().Nanosecond()
fp, _ := os.Create("/tmp/numbers.binary")
rand.Seed(int64(t))
buf := new(bytes.Buffer)
for i := 0; i < 1000; i++ {
k := rand.Int63()
fmt.Println(k)
binary.Write(buf, binary.LittleEndian, k)
// write the buffer
fp.Write(buf.Bytes())
}
fmt.Println("goodbye")
fp.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment