Create a gist now

Instantly share code, notes, and snippets.

@nise-nabe /follow.go
Last active Aug 29, 2015

What would you like to do?
package main
import (
"fmt"
"math/rand"
"strings"
)
type Member struct {
Id int
FollowMember map[int]Member
}
func (m Member) Follow(fm Member) {
m.FollowMember[fm.Id] = fm
}
func (m Member) IsFollow(fm Member) bool {
_, exist := m.FollowMember[fm.Id]
return exist
}
func main() {
followNum := []int{0, 10, 20, 25, 50, 100, 120, 250, 500, 700}
ms := make([]Member, len(followNum)*100)
for i := range ms {
ms[i] = Member{i, make(map[int]Member, 0)}
}
for fi, f := range followNum {
s, e := fi*100, (fi+1)*100
for _, m := range ms[s:e] {
for x := 0; x < f; x++ {
var fm Member
for fm = ms[rand.Intn(len(ms))]; m.IsFollow(fm); fm = ms[rand.Intn(len(ms))] {
}
m.Follow(fm)
}
}
}
for _, m := range ms {
fmt.Println("INSERT INTO follow ('follow_from', 'follow_to') VALUES")
str := make([]string, len(m.FollowMember))
for i, fm := range m.FollowMember {
str[i] = fmt.Sprint("(", m.Id, ",", fm.Id, ")")
}
fmt.Println(strings.Join(str, ","), ";")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment