// GenerateExample produces a random array value.
504049
func (a *Array) GenerateExample(r *RandomGenerator, seen []string) interface{} {
	count := r.Int()%3 + 1
	res := make([]interface{}, count)
	for i := 0; i < count; i++ {
		res[i] = a.ElemType.Type.GenerateExample(r, seen)
	}
	return a.MakeSlice(res)
}
235244
func (eg *exampleGenerator) generateValidatedPatternExample() interface{} {
	if !eg.hasPatternValidation() {
		return false
	}
	pattern := eg.a.Validation.Pattern
	example, err := regen.Generate(pattern)
	if err != nil {
		return eg.r.faker.Name()
	}
	return example
}
767008
func CreateDefaultGetSamples(names ...string) GetSamplesInteractor {
	var samples []*SampleEntity
	for _, item := range names {
		samples = append(samples, &SampleEntity{
			ID:   uuid.NewV4().String(),
			Name: item,
		})
	}
	return GetSamplesInteractorImpl{Samples: samples}
}
815857
func Generate(args map[string]string) string {
	p := pattern.New(args)

	return p.SvgStr()
}
1359286
func NewUniformSample(reservoirSize int) Sample {
	if !Enabled {
		return NilSample{}
	}
	return &UniformSample{
		reservoirSize: reservoirSize,
		values:        make([]int64, 0, reservoirSize),
	}
}
1018051
func (p Primitive) GenerateExample(r *RandomGenerator, seen []string) interface{} {
	switch p {
	case Boolean:
		return r.Bool()
	case Integer:
		return r.Int()
	case Number:
		return r.Float64()
	case String:
		return r.String()
	case DateTime:
		return r.DateTime()
	case UUID:
		return r.UUID().String() // Generate string to can be JSON marshaled
	case Any:
		// to not make it too complicated, pick one of the primitive types
		return anyPrimitive[r.Int()%len(anyPrimitive)].GenerateExample(r, seen)
	case File:
		return r.File()
	default:
		panic("unknown primitive type") // bug
	}
}
650714
func NewSampleJSONBuilder() *SampleJSONBuilder {
	jb := &SampleJSONBuilder{
		_properties:        map[string]*SamplePropertyInfo{},
		_jsonPropertyMap:   map[string]*SamplePropertyInfo{},
		_structPropertyMap: map[string]*SamplePropertyInfo{},
		ID: &SamplePropertyInfo{
			fieldName: "ID",
			jsonName:  "id",
			Encoder: func(src *Sample, dest *SampleJSON) error {
				if src == nil {
					return nil
				}
				dest.ID = src.ID
				return nil
			},
			Decoder: func(src *SampleJSON, dest *Sample) error {
				if src == nil {
					return nil
				}
				dest.ID = src.ID
				return nil
			},
		},
	}
	jb._structPropertyMap["ID"] = jb.ID
	jb._jsonPropertyMap["id"] = jb.ID
	return jb
}
1264019
func NewRandomGenerator(seed string) *RandomGenerator {
	hasher := md5.New()
	hasher.Write([]byte(seed))
	sint := int64(binary.BigEndian.Uint64(hasher.Sum(nil)))
	source := rand.NewSource(sint)
	ran := rand.New(source)
	faker := &faker.Faker{
		Language: "end",
		Dict:     faker.Dict["en"],
		Rand:     ran,
	}
	return &RandomGenerator{
		Seed:  seed,
		faker: faker,
		rand:  ran,
	}
}
617349
func (c *FakeSamples) Create(sample *v1alpha1.Sample) (result *v1alpha1.Sample, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewCreateAction(samplesResource, c.ns, sample), &v1alpha1.Sample{})

	if obj == nil {
		return nil, err
	}
	return obj.(*v1alpha1.Sample), err
}
687110
func (g *Generator) Generate() (_ []string, err error) {
	if g.API == nil {
		return nil, fmt.Errorf("missing API definition, make sure design is properly initialized")
	}

	go utils.Catch(nil, func() { g.Cleanup() })

	defer func() {
		if err != nil {
			g.Cleanup()
		}
	}()

	if g.AppPkg == "" {
		g.AppPkg = "app"
	}
	g.smartenPkg()
	elems := strings.Split(g.AppPkg, "/")
	pkgName := elems[len(elems)-1]
	codegen.Reserved[pkgName] = true

	err = g.API.IterateResources(func(r *design.ResourceDefinition) error {
		var (
			filename string
			err      error
		)
		if g.Resource == "" || g.Resource == r.Name {
			filename, err = genmain.GenerateController(g.Force, g.Regen, g.AppPkg, g.OutDir, g.Pkg, r.Name, r)
		}

		if err != nil {
			return err
		}
		g.genfiles = append(g.genfiles, filename)

		return nil
	})
	if err != nil {
		return nil, err
	}

	return g.genfiles, err
}
1230220
func NewExpDecaySample(reservoirSize int, alpha float64) Sample {
	if !Enabled {
		return NilSample{}
	}
	s := &ExpDecaySample{
		alpha:         alpha,
		reservoirSize: reservoirSize,
		t0:            time.Now(),
		values:        newExpDecaySampleHeap(reservoirSize),
	}
	s.t1 = s.t0.Add(rescaleThreshold)
	return s
}
363205
func NewSampleFJSONBuilder() *SampleFJSONBuilder {
	jb := &SampleFJSONBuilder{
		_properties:        map[string]*SampleFPropertyInfo{},
		_jsonPropertyMap:   map[string]*SampleFPropertyInfo{},
		_structPropertyMap: map[string]*SampleFPropertyInfo{},
		A: &SampleFPropertyInfo{
			fieldName: "A",
			jsonName:  "a",
			Encoder: func(src *SampleF, dest *SampleFJSON) error {
				if src == nil {
					return nil
				}
				dest.A = src.A
				return nil
			},
			Decoder: func(src *SampleFJSON, dest *SampleF) error {
				if src == nil {
					return nil
				}
				dest.A = src.A
				return nil
			},
		},
		B: &SampleFPropertyInfo{
			fieldName: "B",
			jsonName:  "b",
			Encoder: func(src *SampleF, dest *SampleFJSON) error {
				if src == nil {
					return nil
				}
				dest.B = src.B
				return nil
			},
			Decoder: func(src *SampleFJSON, dest *SampleF) error {
				if src == nil {
					return nil
				}
				dest.B = src.B
				return nil
			},
		},
	}
	jb._structPropertyMap["A"] = jb.A
	jb._jsonPropertyMap["a"] = jb.A
	jb._structPropertyMap["B"] = jb.B
	jb._jsonPropertyMap["b"] = jb.B
	return jb
}
1342361
func AddSample(key []string, val float32) {
	normalizeKeys(key)

	GetMetrics().AddSample(key, val)
}
92915
func (a *APIDefinition) RandomGenerator() *RandomGenerator {
	if a.rand == nil {
		a.rand = NewRandomGenerator(a.Name)
	}
	return a.rand
}
574500
func (a *AttributeDefinition) GenerateExample(rand *RandomGenerator, seen []string) interface{} {
	if a.Example != nil {
		return a.Example
	}
	if Design.NoExamples {
		return nil
	}

	// Avoid infinite loops
	var key string
	if mt, ok := a.Type.(*MediaTypeDefinition); ok {
		key = mt.Identifier
	} else if ut, ok := a.Type.(*UserTypeDefinition); ok {
		key = ut.TypeName
	}
	if key != "" {
		count := 0
		for _, k := range seen {
			if k == key {
				count++
			}
		}
		if count > 1 {
			// Only go a couple of levels deep
			return nil
		}
		seen = append(seen, key)
	}

	switch {
	case a.Type.IsArray():
		a.Example = a.arrayExample(rand, seen)

	case a.Type.IsHash():
		a.Example = a.hashExample(rand, seen)

	case a.Type.IsObject():
		a.Example = a.objectExample(rand, seen)

	default:
		a.Example = newExampleGenerator(a, rand).Generate(seen)
	}

	return a.Example
}
880093
func NewSampleJSONBuilder() *SampleJSONBuilder {
	jb := &SampleJSONBuilder{
		_properties:        map[string]*SamplePropertyInfo{},
		_jsonPropertyMap:   map[string]*SamplePropertyInfo{},
		_structPropertyMap: map[string]*SamplePropertyInfo{},
		A: &SamplePropertyInfo{
			fieldName: "A",
			jsonName:  "foo!",
			Encoder: func(src *Sample, dest *SampleJSON) error {
				if src == nil {
					return nil
				}
				dest.A = src.A
				return nil
			},
			Decoder: func(src *SampleJSON, dest *Sample) error {
				if src == nil {
					return nil
				}
				dest.A = src.A
				return nil
			},
		},
		B: &SamplePropertyInfo{
			fieldName: "B",
			jsonName:  "b",
			Encoder: func(src *Sample, dest *SampleJSON) error {
				if src == nil {
					return nil
				}
				dest.B = src.B
				return nil
			},
			Decoder: func(src *SampleJSON, dest *Sample) error {
				if src == nil {
					return nil
				}
				dest.B = src.B
				return nil
			},
		},
	}
	jb._structPropertyMap["A"] = jb.A
	jb._jsonPropertyMap["foo!"] = jb.A
	jb._structPropertyMap["B"] = jb.B
	jb._jsonPropertyMap["b"] = jb.B
	return jb
}
92751
func GenerateRandomString(s int) (string, error) {
	b, err := GenerateRandomBytes(s)
	return base64.URLEncoding.EncodeToString(b), err
}