genArray emits an array with 0–5 elements (including the empty array []).
(r *rand.Rand, depth int, buf *[]byte)
| 218 | |
| 219 | // genArray emits an array with 0–5 elements (including the empty array []). |
| 220 | func genArray(r *rand.Rand, depth int, buf *[]byte) { |
| 221 | *buf = append(*buf, '[') |
| 222 | n := r.Intn(6) // 0..5 elements |
| 223 | for i := 0; i < n; i++ { |
| 224 | if i > 0 { |
| 225 | *buf = append(*buf, ',') |
| 226 | } |
| 227 | genValue(r, depth+1, buf) |
| 228 | } |
| 229 | *buf = append(*buf, ']') |
| 230 | } |
| 231 | |
| 232 | // genKey emits a JSON object key (a double-quoted string). The key content |
| 233 | // is drawn from a weighted distribution that includes the cases most likely |