Golang : Flip coin example

This is a simple program to simulate flip coin that I use to train a small artificial intelligence program. Basically what it does is to randomly pick an item from a two elements slice.

Here you go!

 package main

 import (

 func main() {

 coin := []string{


 // flip the coin
 side := coin[rand.Intn(len(coin))]

 fmt.Println("Flipped the coin and you get : ", side)



Flipped the coin and you get : heads

$ ./flip

Flipped the coin and you get : heads

$ ./flip

Flipped the coin and you get : tails



Tags : golang flip-coin random

Adam Ng By Adam Ng

Get in touch at Google Plus or stay updated on Facebook.

IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.