MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / doRandomJSON

Function doRandomJSON

pkg/util/json/random.go:53–92  ·  view source on GitHub ↗
(complexity int, rng *rand.Rand)

Source from the content-addressed store, hash-verified

51}
52
53func doRandomJSON(complexity int, rng *rand.Rand) interface{} {
54 if complexity <= 0 || rng.Intn(10) == 0 {
55 switch rng.Intn(5) {
56 case 0:
57 return randomJSONString(rng)
58 case 1:
59 return randomJSONNumber(rng)
60 case 2:
61 return true
62 case 3:
63 return false
64 case 4:
65 return nil
66 }
67 }
68 complexity--
69 switch rng.Intn(3) {
70 case 0:
71 result := make([]interface{}, 0)
72 for complexity > 0 {
73 amount := 1 + rng.Intn(complexity)
74 complexity -= amount
75 result = append(result, doRandomJSON(amount, rng))
76 }
77 return result
78 case 1:
79 result := make(map[string]interface{})
80 for complexity > 0 {
81 amount := 1 + rng.Intn(complexity)
82 complexity -= amount
83 result[randomJSONString(rng).(string)] = doRandomJSON(amount, rng)
84 }
85 return result
86 default:
87 j, _ := Random(complexity, rng)
88 encoding, _ := EncodeJSON(nil, j)
89 encoded, _ := newEncodedFromRoot(encoding)
90 return encoded
91 }
92}

Callers 1

RandomFunction · 0.85

Calls 6

randomJSONStringFunction · 0.85
randomJSONNumberFunction · 0.85
EncodeJSONFunction · 0.85
newEncodedFromRootFunction · 0.85
RandomFunction · 0.70
IntnMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…