func (g *UniqueGenerator) ContNum() Number {
	return g.contNum
}
ContNum returns generated container number.
package cont
import (
	"errors"
	"fmt"
	"math/rand"
	"strings"
	"time"
)
type GeneratorBuilder struct {
	codes                []string
	count                int
	start                int
	end                  int
	exclCheckDigit10     bool
	exclTranspositionErr bool
}
func NewUniqueGeneratorBuilder() *GeneratorBuilder {
	return &GeneratorBuilder{
		count: 1,
		start: -1,
		end:   -1,
	}
}
func (gb *GeneratorBuilder) OwnerCodes(codes []string) *GeneratorBuilder {
	gb.codes = codes
	return gb
}
func (gb *GeneratorBuilder) Count(count int) *GeneratorBuilder {
	gb.count = count
	return gb
}
func (gb *GeneratorBuilder) Start(start int) *GeneratorBuilder {
	gb.start = start
	return gb
}
func (gb *GeneratorBuilder) End(end int) *GeneratorBuilder {
	gb.end = end
	return gb
}
func (gb *GeneratorBuilder) ExcludeCheckDigit10(exclude bool) *GeneratorBuilder {
	gb.exclCheckDigit10 = exclude
	return gb
}
func (gb *GeneratorBuilder) ExcludeTranspositionErr(exclude bool) *GeneratorBuilder {
	gb.exclTranspositionErr = exclude
	return gb
}
func (gb *GeneratorBuilder) Build() (*UniqueGenerator, error) {
	lenCodes := len(gb.codes)
	if lenCodes < 1 {
		return nil, errors.New("cannot generate container numbers without owner codes")
	}
	serialNums := 1000000
	if gb.exclCheckDigit10 {
		serialNums = 909091
	}
	if gb.count > lenCodes*serialNums {
		return nil, fmt.Errorf("count %d exceeds limit of %d (%d owners * %d serial numbers)",
			gb.count, lenCodes*serialNums, lenCodes, serialNums)
	}
	var serialNumIt serialNumIt
	var count int
	if gb.start > -1 && gb.end > -1 {
		serialNumIt = newSeqSerialNumIt(gb.start)
		if gb.start <= gb.end {
			count = gb.end + 1 - gb.start
		} else {
			count = gb.end + 1000000 + 1 - gb.start
		}
	}
	if gb.start > -1 && gb.end == -1 {
		serialNumIt = newSeqSerialNumIt(gb.start)
		count = gb.count
	}
	if gb.end > -1 && gb.start == -1 {
		serialNumIt = newSeqSerialNumIt(gb.end + 1 - gb.count)
		count = gb.count
	}
	if gb.start == -1 && gb.end == -1 {
		if gb.count < 1 {
			return nil, fmt.Errorf("count %d is lower than minimum count 1", gb.count)
		}
		serialNumIt = newRandSerialNumIt()
		count = gb.count
	}
	rand.Shuffle(lenCodes, func(i, j int) {
		gb.codes[i], gb.codes[j] = strings.ToUpper(gb.codes[j]), strings.ToUpper(gb.codes[i])
	})
	return &UniqueGenerator{
		codes:                gb.codes,
		lenCodes:             lenCodes,
		serialNumIt:          serialNumIt,
		count:                count,
		exclCheckDigit10:     gb.exclCheckDigit10,
		exclTranspositionErr: gb.exclTranspositionErr,
	}, nil
}
type UniqueGenerator struct {
	codes                []string
	lenCodes             int
	ownerOffset          int
	serialNumIt          serialNumIt
	count                int
	contNum              Number
	generatedCount       int
	exclCheckDigit10     bool
	exclTranspositionErr bool
}
func (g *UniqueGenerator) Generate() bool {
	code := g.codes[(g.serialNumIt.num()+g.ownerOffset)%g.lenCodes]
	serialNum := fmt.Sprintf("%06d", g.serialNumIt.num())
	checkDigit := CalcCheckDigit(code, "U", serialNum)
	if g.serialNumIt.isLast() {
		g.ownerOffset++
	}
	g.serialNumIt.increment()
	if g.exclCheckDigit10 && checkDigit == 10 {
		return g.Generate()
	}
	if g.exclTranspositionErr && len(CheckTransposition(code, "U", serialNum)) > 0 {
		return g.Generate()
	}
	g.contNum = newNum(code, "U", serialNum, checkDigit%10)
	g.generatedCount++
	return g.generatedCount <= g.count
}