Last active
January 5, 2024 02:36
-
-
Save ryogrid/3435ccf49c152aa8c94fc3c7a4b249e8 to your computer and use it in GitHub Desktop.
dummy graph data generator (exection: go run gen_graph_data.go)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"math/rand" | |
"os" | |
"strconv" | |
) | |
const USER_NUM_BASE = 100 * 10000 // 1M | |
const AVERAGE_FOLLOW = 100 | |
func makeUserList() []*string { | |
dupMap := make(map[string]bool) | |
userList := make([]*string, USER_NUM_BASE*2) | |
num := 0 | |
randGenerator := rand.New(rand.NewSource(2024)) | |
for num < USER_NUM_BASE*2 { | |
userID := randGenerator.Intn(USER_NUM_BASE * 10) | |
if _, ok := dupMap[string(userID)]; ok { | |
// duplicated | |
continue | |
} else { | |
dupMap[string(userID)] = true | |
tmpStr1 := strconv.FormatInt(int64(userID), 16) + "X" | |
userList[num] = &tmpStr1 | |
tmpStr2 := strconv.FormatInt(int64(userID), 16) + "Y" | |
userList[num+1] = &tmpStr2 | |
num += 2 | |
} | |
} | |
return userList | |
} | |
func main() { | |
file, err := os.Create("./social_graph.csv") | |
writer := bufio.NewWriter(file) | |
defer file.Close() | |
if err != nil { | |
log.Fatal(err) | |
} | |
userList := makeUserList() | |
randGenerator := rand.New(rand.NewSource(2023)) | |
for ii := 0; ii < USER_NUM_BASE*2; ii++ { | |
if ii%10000 == 0 { | |
fmt.Println(ii) | |
} | |
dupMap := make(map[int]bool) | |
if ii%2 == 0 { | |
_, err = writer.WriteString(*userList[ii] + "," + *userList[ii+1] + "\n") | |
if err != nil { | |
log.Fatal(err) | |
} | |
dupMap[ii+1] = true | |
_, err = writer.WriteString(*userList[ii+1] + "," + *userList[ii] + "\n") | |
if err != nil { | |
log.Fatal(err) | |
} | |
} else { | |
dupMap[ii-1] = true | |
} | |
for jj := 0; jj < AVERAGE_FOLLOW; jj++ { | |
followIdx := randGenerator.Intn(USER_NUM_BASE * 2) | |
if _, ok := dupMap[followIdx]; ok { | |
// duplicated | |
continue | |
} else { | |
dupMap[followIdx] = true | |
_, err = writer.WriteString(*userList[ii] + "," + *userList[followIdx] + "\n") | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment