@@ -3,7 +3,7 @@ package main
33import (
44 "context"
55 "fmt"
6- "math/rand"
6+ "math/rand/v2 "
77 "strings"
88 "time"
99)
@@ -13,11 +13,11 @@ func runSyntheticMode() error {
1313 generator := NewSyntheticDataGenerator ()
1414
1515 // Generate a random number of synthetic models (1-3)
16- numModels := generator .rand .Intn (3 ) + 1
16+ numModels := generator .rand .IntN (3 ) + 1
1717 fmt .Printf ("Generating %d synthetic models for testing...\n " , numModels )
1818
1919 var models []ProcessedModel
20- for i := 0 ; i < numModels ; i ++ {
20+ for i := range numModels {
2121 model := generator .GenerateProcessedModel ()
2222 models = append (models , model )
2323 fmt .Printf ("Generated synthetic model: %s\n " , model .ModelID )
@@ -42,14 +42,14 @@ type SyntheticDataGenerator struct {
4242// NewSyntheticDataGenerator creates a new synthetic data generator
4343func NewSyntheticDataGenerator () * SyntheticDataGenerator {
4444 return & SyntheticDataGenerator {
45- rand : rand .New (rand .NewSource ( time .Now ().UnixNano ())),
45+ rand : rand .New (rand .NewPCG ( uint64 ( time .Now ().UnixNano ()), 0 )),
4646 }
4747}
4848
4949// GenerateProcessedModelFile creates a synthetic ProcessedModelFile
5050func (g * SyntheticDataGenerator ) GenerateProcessedModelFile () ProcessedModelFile {
5151 fileTypes := []string {"model" , "readme" , "other" }
52- fileType := fileTypes [g .rand .Intn (len (fileTypes ))]
52+ fileType := fileTypes [g .rand .IntN (len (fileTypes ))]
5353
5454 var path string
5555 var isReadme bool
@@ -68,7 +68,7 @@ func (g *SyntheticDataGenerator) GenerateProcessedModelFile() ProcessedModelFile
6868
6969 return ProcessedModelFile {
7070 Path : path ,
71- Size : int64 (g .rand .Intn (1000000000 ) + 1000000 ), // 1MB to 1GB
71+ Size : int64 (g .rand .IntN (1000000000 ) + 1000000 ), // 1MB to 1GB
7272 SHA256 : g .randomSHA256 (),
7373 IsReadme : isReadme ,
7474 FileType : fileType ,
@@ -80,19 +80,19 @@ func (g *SyntheticDataGenerator) GenerateProcessedModel() ProcessedModel {
8080 authors := []string {"microsoft" , "meta" , "google" , "openai" , "anthropic" , "mistralai" , "huggingface" }
8181 modelNames := []string {"llama" , "gpt" , "claude" , "mistral" , "gemma" , "phi" , "qwen" , "codellama" }
8282
83- author := authors [g .rand .Intn (len (authors ))]
84- modelName := modelNames [g .rand .Intn (len (modelNames ))]
83+ author := authors [g .rand .IntN (len (authors ))]
84+ modelName := modelNames [g .rand .IntN (len (modelNames ))]
8585 modelID := fmt .Sprintf ("%s/%s-%s" , author , modelName , g .randomString (6 ))
8686
8787 // Generate files
88- numFiles := g .rand .Intn (5 ) + 2 // 2-6 files
88+ numFiles := g .rand .IntN (5 ) + 2 // 2-6 files
8989 files := make ([]ProcessedModelFile , numFiles )
9090
9191 // Ensure at least one model file and one readme
9292 hasModelFile := false
9393 hasReadme := false
9494
95- for i := 0 ; i < numFiles ; i ++ {
95+ for i := range numFiles {
9696 files [i ] = g .GenerateProcessedModelFile ()
9797 if files [i ].FileType == "model" {
9898 hasModelFile = true
@@ -140,27 +140,27 @@ func (g *SyntheticDataGenerator) GenerateProcessedModel() ProcessedModel {
140140
141141 // Generate sample metadata
142142 licenses := []string {"apache-2.0" , "mit" , "llama2" , "gpl-3.0" , "bsd" , "" }
143- license := licenses [g .rand .Intn (len (licenses ))]
143+ license := licenses [g .rand .IntN (len (licenses ))]
144144
145145 sampleTags := []string {"llm" , "gguf" , "gpu" , "cpu" , "text-to-text" , "chat" , "instruction-tuned" }
146- numTags := g .rand .Intn (4 ) + 3 // 3-6 tags
146+ numTags := g .rand .IntN (4 ) + 3 // 3-6 tags
147147 tags := make ([]string , numTags )
148- for i := 0 ; i < numTags ; i ++ {
149- tags [i ] = sampleTags [g .rand .Intn (len (sampleTags ))]
148+ for i := range numTags {
149+ tags [i ] = sampleTags [g .rand .IntN (len (sampleTags ))]
150150 }
151151 // Remove duplicates
152152 tags = g .removeDuplicates (tags )
153153
154154 // Optionally include icon (50% chance)
155155 icon := ""
156- if g .rand .Intn (2 ) == 0 {
156+ if g .rand .IntN (2 ) == 0 {
157157 icon = fmt .Sprintf ("https://cdn-avatars.huggingface.co/v1/production/uploads/%s.png" , g .randomString (24 ))
158158 }
159159
160160 return ProcessedModel {
161161 ModelID : modelID ,
162162 Author : author ,
163- Downloads : g .rand .Intn (1000000 ) + 1000 ,
163+ Downloads : g .rand .IntN (1000000 ) + 1000 ,
164164 LastModified : g .randomDate (),
165165 Files : files ,
166166 PreferredModelFile : preferredModelFile ,
@@ -180,7 +180,7 @@ func (g *SyntheticDataGenerator) randomString(length int) string {
180180 const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
181181 b := make ([]byte , length )
182182 for i := range b {
183- b [i ] = charset [g .rand .Intn (len (charset ))]
183+ b [i ] = charset [g .rand .IntN (len (charset ))]
184184 }
185185 return string (b )
186186}
@@ -189,14 +189,14 @@ func (g *SyntheticDataGenerator) randomSHA256() string {
189189 const charset = "0123456789abcdef"
190190 b := make ([]byte , 64 )
191191 for i := range b {
192- b [i ] = charset [g .rand .Intn (len (charset ))]
192+ b [i ] = charset [g .rand .IntN (len (charset ))]
193193 }
194194 return string (b )
195195}
196196
197197func (g * SyntheticDataGenerator ) randomDate () string {
198198 now := time .Now ()
199- daysAgo := g .rand .Intn (365 ) // Random date within last year
199+ daysAgo := g .rand .IntN (365 ) // Random date within last year
200200 pastDate := now .AddDate (0 , 0 , - daysAgo )
201201 return pastDate .Format ("2006-01-02T15:04:05.000Z" )
202202}
@@ -220,5 +220,5 @@ func (g *SyntheticDataGenerator) generateReadmeContent(modelName, author string)
220220 fmt .Sprintf ("# %s Language Model\n \n Developed by %s, this model represents state-of-the-art performance in natural language understanding and generation.\n \n ## Key Features\n \n - Multilingual support\n - Context-aware responses\n - Efficient memory usage\n - Fast inference speed\n \n ## Applications\n \n - Chatbots and virtual assistants\n - Content generation\n - Code completion\n - Educational tools" , strings .Title (modelName ), author ),
221221 }
222222
223- return templates [g .rand .Intn (len (templates ))]
223+ return templates [g .rand .IntN (len (templates ))]
224224}
0 commit comments