func makeFloatFunc()

in pkg/genlib/generator_interface.go [224:248]


func makeFloatFunc(fieldCfg ConfigField, field Field) func() float64 {
	minValue, _ := fieldCfg.Range.MinAsFloat64()
	maxValue, err := fieldCfg.Range.MaxAsFloat64()
	// maxValue not set, let's set it to 0 for the sake of the switch above
	if err != nil {
		maxValue = 0
	}

	var dummyFunc func() float64

	switch {
	case maxValue > 0:
		dummyFunc = func() float64 { return minValue + customRand.Float64()*(maxValue-minValue) }
	case len(field.Example) == 0:
		dummyFunc = func() float64 { return customRand.Float64() * 10 }
	default:
		totDigit := len(field.Example)
		max := math.Pow10(totDigit)
		dummyFunc = func() float64 {
			return customRand.Float64() * max
		}
	}

	return dummyFunc
}