2021-04-19 13:42:47 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
2021-02-22 09:58:34 +08:00
|
|
|
package funcutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2021-05-24 10:50:37 +08:00
|
|
|
var Rand *rand.Rand = nil
|
|
|
|
|
2021-02-22 09:58:34 +08:00
|
|
|
func init() {
|
2021-05-24 10:50:37 +08:00
|
|
|
Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
|
2021-02-22 09:58:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
|
|
|
|
func RandomString(n int) string {
|
|
|
|
b := make([]rune, n)
|
|
|
|
for i := range b {
|
2021-05-24 10:50:37 +08:00
|
|
|
b[i] = letterRunes[Rand.Intn(len(letterRunes))]
|
2021-02-22 09:58:34 +08:00
|
|
|
}
|
|
|
|
return string(b)
|
|
|
|
}
|