Correct the function GenerateName #6

Merged
lx merged 1 commit from Correct_Test_GenerateName into main 2021-07-29 08:02:29 +00:00

View file

@ -32,7 +32,9 @@ func PrintError(LDAPError error) {
//Generate an unique name, which store in all_names //Generate an unique name, which store in all_names
func (inst *instance) GenerateName() (name string) { func (inst *instance) GenerateName() (name string) {
alphabet := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" alphabet := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y",
"Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "é", "è", "ê", "ë", "à", "@", "â", "ä", "û", "ü", "ù", "$", "£", "%", "ø", "€"}
length := R.Intn(maxlength_generateName) + minlength_generateName length := R.Intn(maxlength_generateName) + minlength_generateName
//Check if this name not exist already //Check if this name not exist already
@ -41,7 +43,7 @@ func (inst *instance) GenerateName() (name string) {
for only_one := true; only_one; _, only_one = allNames.cn[name] { for only_one := true; only_one; _, only_one = allNames.cn[name] {
//Create the name //Create the name
for i := 0; i < length; i++ { for i := 0; i < length; i++ {
name += string(alphabet[R.Intn(len(alphabet))]) name += alphabet[R.Intn(len(alphabet))]
} }
} }