Skip to content

Instantly share code, notes, and snippets.

@ds0nt
Created January 9, 2016 22:47
Show Gist options
  • Save ds0nt/3d64683ed3480b28793a to your computer and use it in GitHub Desktop.
Save ds0nt/3d64683ed3480b28793a to your computer and use it in GitHub Desktop.
rand.go
package main
import "fmt"
type hooray struct {
v []int
}
var ticker = 0
var uhoh = hooray{make([]int, 0)}
func appendStuff(stuff int) {
uhoh.v = append(uhoh.v, stuff)
ticker++
}
func dangerouslyWrite(done chan struct{}) {
i := 0
for {
appendStuff(i)
i++
if i > 1000 {
break
}
}
done <- struct{}{}
}
func rand(max int) int {
done := make(chan struct{})
for index := 0; index < 10; index++ {
go dangerouslyWrite(done)
}
for index := 0; index < 10; index++ {
<-done
}
return max * ticker / 10000
}
func main() {
x := rand(100)
fmt.Println(x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment