Example generates a pseudo-random array value using the given random generator.
(r *ExampleGenerator)
| 418 | // Example generates a pseudo-random array value using the given random |
| 419 | // generator. |
| 420 | func (a *Array) Example(r *ExampleGenerator) any { |
| 421 | count := NewLength(a.ElemType, r) |
| 422 | res := make([]any, count) |
| 423 | for i := range count { |
| 424 | res[i] = a.ElemType.Example(r) |
| 425 | if res[i] == nil { |
| 426 | // Handle the case of recursive data structures |
| 427 | res[i] = make(map[string]any) |
| 428 | } |
| 429 | } |
| 430 | return a.MakeSlice(res) |
| 431 | } |
| 432 | |
| 433 | // MakeSlice examines the key type from the Array and create a slice with |
| 434 | // builtin type if possible. The idea is to avoid generating []any and |