A long time ago I created a cointosser application that would do something like 10,000 coin flips via random.org which was sort of slow. I thought it might be cool to instead transmit the data as an image which can be read by pixels – a 100×100 image is 10,000 trials and the file is pretty small/easy to parse. I wrote a simple prototype of this in Go, and plan on running it on a raspberry pi using its hardware random number generator

package main

import (
  "image"
  "image/color"
  "image/png"
  "math/rand"
  "os"
  "time"
)

func main() {
  img := image.NewRGBA(image.Rect(0, 0, 100, 100))
  random_seed := rand.New(rand.NewSource(time.Now().UnixNano()))

  // For each pixel in the `img` randomly set pixel to black or white
  for x := 0; x < img.Bounds().Max.X; x++ {
    for y := 0; y < img.Bounds().Max.Y; y++ {
      if int(random_seed.Intn(2)) == int(0) {
        img.Set(x, y, color.Black)
      } else {
        img.Set(x, y, color.White)
      }
    }
  }

  // save image out to png file
  export_img, _ := os.Create("random.png")
  defer export_img.Close()
  png.Encode(export_img, img)

}