Created
July 26, 2019 04:15
-
-
Save rschultheis/104e7814a88c65f55bfe384ae35a00b3 to your computer and use it in GitHub Desktop.
make random files in go of various sizes
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 ( | |
"fmt" | |
"io/ioutil" | |
"math/rand" | |
"time" | |
) | |
var ( | |
sizes = []int{100000, 1000000, 1000000, 2000000, 5000000, 10000000, 50000000, 100000000} | |
runeset = []rune("-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
) | |
func main() { | |
for _, size := range sizes { | |
fn := fmt.Sprintf("sample_file_%d.txt", size) | |
token := fmt.Sprintf("sl.") | |
size_prefix := fmt.Sprintf("xXxXx-%d-xXxXx", size) | |
token += size_prefix | |
token += RandomStringFromRuneset(size-len(size_prefix), runeset) | |
file := fmt.Sprintf("token_size: %d\ntoken: %s\nanother_field: value\n", size, token) | |
if err := ioutil.WriteFile(fn, []byte(file), 0644); err != nil { | |
panic(err) | |
} | |
} | |
} | |
func RandomStringFromRuneset(length int, runeset []rune) string { | |
runes := make([]rune, length) | |
runeset_size := len(runeset) | |
rand.Seed(time.Now().UTC().UnixNano()) | |
for i := range runes { | |
runes[i] = runeset[rand.Intn(runeset_size)] | |
} | |
return string(runes) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment