// This returns a thread-safe random source.
166825
func NewSource(seed int64) rand.Source {
	return &lockedSource{
		src: rand.NewSource(seed),
	}
}
262090
func randomInteger() int {
	return rand.Intn(nBoundary.end-nBoundary.start) + nBoundary.start
}
569248
func randHint(possible []Cmd) string {
	l := len(possible)
	if l == 0 {
		return ""
	}

	// Seed random integer
	r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
	i := r.Intn(l)
	cmd := possible[i]
	if hints, ok := commandHints[cmd]; ok {
		item := r.Intn(len(hints))
		if len(hints) > item {
			return hints[item]
		}
	}
	return ""
}
1113859
func NewRandom() (UUID, error) {
	u, err := random.NewUUID()
	if err != nil {
		return Nil, err
	}

	uuid := UUID{}
	copy(uuid[:], u)

	return uuid, nil
}
700084
func GenerateRandomName(prefix string, size int) (string, error) {
	id := make([]byte, 32)
	if _, err := io.ReadFull(rand.Reader, id); err != nil {
		return "", err
	}
	return prefix + hex.EncodeToString(id)[:size], nil
}
79321
func GenerateRandomBytes(size int) ([]byte, error) {
	buf := make([]byte, size)
	if _, err := rand.Read(buf); err != nil {
		return nil, fmt.Errorf("failed to read random bytes: %v", err)
	}
	return buf, nil
}
312770
func getRandom(c context.Context, want int) ([]byte, error) {
	ret := make([]byte, want)
	_, err := cryptorand.Read(c, ret)
	if err != nil {
		logging.WithError(err).Errorf(c, "could not generate random data")
		return nil, err
	}
	return ret, nil
}
97770
func GenerateRandomID() (id string, err error) {
	buf, err := generateSecureRandomData(keyIDSize)
	if err != nil {
		return "", err
	}
	if !validateDataIntegrity(buf, keyIDSize) {
		return "", fmt.Errorf("error in generateRandomID: crypto/rand failed to generate random data")
	}
	id = common.Bytes2Hex(buf)
	return id, err
}
386716
func (enc *Encoding) Random(n int) (string, error) {
	buf := make([]byte, n)
	_, err := rand.Reader.Read(buf)
	if err != nil {
		return "", err
	}
	return enc.EncodeToString(buf), nil
}
1238147
func (r *BulkUpdateRequest) ReturnSource(source bool) *BulkUpdateRequest {
	r.returnSource = &source
	r.source = nil
	return r
}
1075537
func RandPort() (int, error) {
	var port int
	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
	if err != nil {
		return port, err
	}
	listener, err := net.ListenTCP("tcp", addr)
	if err != nil {
		return port, fmt.Errorf("could not listen to find random port: %v", err)
	}
	randAddr := listener.Addr().(*net.TCPAddr)
	if err := listener.Close(); err != nil {
		return port, fmt.Errorf("could not close random listener: %v", err)
	}
	return randAddr.Port, nil
}
555507
func (nc *Conn) shufflePool() {
	if len(nc.srvPool) <= 1 {
		return
	}
	source := rand.NewSource(time.Now().UnixNano())
	r := rand.New(source)
	for i := range nc.srvPool {
		j := r.Intn(i + 1)
		nc.srvPool[i], nc.srvPool[j] = nc.srvPool[j], nc.srvPool[i]
	}
}
971467
func (c *Client) Random(args []string) (Random, error) {
	argsStr := strings.Join(args, " ")

	req, err := c.NewRequest("/gifs/random?tag=" + argsStr)
	if err != nil {
		return Random{}, err
	}

	var random Random
	if _, err = c.Do(req, &random); err != nil {
		return Random{}, err
	}

	// Check if the first character in Data is a [
	if random.RawData == nil || random.RawData[0] == '[' {
		return Random{}, ErrNoImageFound
	}

	var d RandomData

	err = json.Unmarshal(random.RawData, &d)
	if err != nil {
		return Random{}, err
	}

	random.Data = d

	return random, nil
}
1290831
func NewRandom(n int) Cache {
	if n < 1 {
		return nil
	}
	return &Random{
		table: make(map[int64]bgzf.Block, n),
		cap:   n,
	}
}
658153
func GetRandomBytes(len int) ([]byte, error) {
	if len < 0 {
		return nil, errors.New("Len must be larger than 0")
	}

	buffer := make([]byte, len)

	n, err := rand.Read(buffer)
	if err != nil {
		return nil, err
	}
	if n != len {
		return nil, fmt.Errorf("Buffer not filled. Requested [%d], got [%d]", len, n)
	}

	return buffer, nil
}
833357
func pseudoRand() string {
	ts := time.Now().UnixNano()
	lastUsedTimeLock.Lock()
	if ts <= lastUsedTime {
		ts = lastUsedTime + 1
	}
	lastUsedTime = ts
	lastUsedTimeLock.Unlock()

	// Hash the state to get a smaller pseudorandom string.
	h := sha256.New()
	fmt.Fprintf(h, "%v_%v", os.Getpid(), ts)
	sum := h.Sum(nil)
	digest := base64.RawURLEncoding.EncodeToString(sum)
	return digest[:12]
}
986927
func Random(length int) (string, error) {
	if length == 0 {
		return "", nil
	}
	output := make([]byte, 0, length)

	// Request a bit more than length to reduce the chance
	// of needing more than one batch of random bytes
	batchSize := length + length/4

	for {
		buf, err := uuid.GenerateRandomBytes(batchSize)
		if err != nil {
			return "", err
		}

		for _, b := range buf {
			// Avoid bias by using a value range that's a multiple of 62
			if b < (csLen * 4) {
				output = append(output, charset[b%csLen])

				if len(output) == length {
					return string(output), nil
				}
			}
		}
	}
}