# [Solved]Random Player Name Issue...

#### Kolossoni

Level 3
I've been working on a trigger that would allow a certain race to have different names (randomly) depending on the number of players.

For example:
Player1
Race = Human
Names(1) = "..."
Names(2) = "..."
Names(3) = "Knights of Lordearon" <---Let's say this one gets picked (randomly)
Names(4) = "..."
Names(5) = "..."

Player2
Race = Human
Names(1) = "..."
Names(2) = "..."
Names(3) = Knights of Lordearon <---Now this name will be unavailable for the next player
Names(4) = "..."
Names(5) = "..."

and so on...

I've tried here and there, but it doesn't really work...

Can anyone help?
Thnx.

#### Chaosium

Level 14
You can create a Boolean variable with an array that corresponds to your name, like NamesBoolean[1], NamesBoolean[2], etc. Then, when picking a name, you use the boolean to check whether the name has already been picked or not.

#### Chaosy

Tutorial Reviewer
Level 40
If you have

something[1]
something[2]
...

number = 5

random = random number between 1 and number
do something with something[random]
something[random] = something[number]
number = number - 1

#### Kolossoni

Level 3
If you have

something[1]
something[2]
...

number = 5

random = random number between 1 and number
do something with something[random]
something[random] = something[number]
number = number - 1

Ummmmmm, I 'kinda' get it yet I can't fully grasp what you mean by "do something".
There's too many "something"s that I can't understand it!

Can you explain it a bit, I dunno... "straightfoward"...? I guess?

#### Chaosy

Tutorial Reviewer
Level 40
set superDuperArray[1]
set superDuperArray[2]
set superDuperArray[3]
set superDuperArray[4]
set superDuperArray[5] <--- size of array stored in a variable ("number" in my example)

set number = 5

randomOfArray = random number between 1 and number

Do whatever you want with superDuperArray[randomOfArray]

set superDuperArray[randomOfArray] = superDuperArray[number]
set number = number - 1

Not really sure how to explain it better.

#### Athur12A2

Level 10
Using array is the best method. StringName[array] with MaxName = 5

StringName[1] = A
StringName[2] = B
StringName[3] = C
StringName[4] = D
StringName[5] = E

P1 chose B. Then

set StringName[2] = StringName[5]
set MaxName = MaxName - 1

P2 then have:

StringName[1] = A
StringName[2] = E
StringName[3] = C
StringName[4] = D

#### Kolossoni

Level 3
set superDuperArray[1]
set superDuperArray[2]
set superDuperArray[3]
set superDuperArray[4]
set superDuperArray[5] <--- size of array stored in a variable ("number" in my example)

set number = 5

randomOfArray = random number between 1 and number

Do whatever you want with superDuperArray[randomOfArray]

set superDuperArray[randomOfArray] = superDuperArray[number]
set number = number - 1

Not really sure how to explain it better.

Haha, I get it, Loud and clear.

THNX a lot everyone. Imma try them out!

#### Kolossoni

Level 3
Hey guys, I've got an issue again...

Everything was going perfectly until I saw that the (random) names for each players (depending on their races) suddenly had duplicate names!
So for example, if there were 4 human players, two of them would have comepletely different names, and the rest of the two will have the same names!

I mainly followed Chaosy's steps and while I was trying to solve this on my own, I've noticed that the "set number = number - 1" suggested by Chaosy doesn't really specify the exact name that has been picked before...
So I think the system just takes a random name out of the possible selections [in this case an unused name was taken out], when I want the specific, picked name to be taken out...

Any suggestions to prevent this from happening...?

E

#### EdgeOfChaos

Chaosy's method is correct; can you post your implementation of it?

Basically his method moves the final item of the array down to replace the randomly selected one and then "shrinks" the array (not really, but the number is decreased so it functions like you did). Are you sure you're decreasing number by one and making sure to generate a random bounded by that number correctly?

#### Dr Super Good

Spell Reviewer
Level 63
I mainly followed Chaosy's steps and while I was trying to solve this on my own, I've noticed that the "set number = number - 1" suggested by Chaosy doesn't really specify the exact name that has been picked before...
So I think the system just takes a random name out of the possible selections [in this case an unused name was taken out], when I want the specific, picked name to be taken out...
The idea is you select an element randomly in the list, remove that element from the list and then use that element. Unless you have duplicates in your list, each time a unique element will be removed until the list is empty.

To remove from a simple array list without caring about order, set the element being removed to the end of the list and decrement list length by 1.

#### Kolossoni

Level 3
Okay, after taking everyone's advice, I 'think' I got it under control...
I guess I messed up one of the steps Chaosy stated before!
Thnx everyone!

Replies
3
Views
218
Replies
16
Views
1K
Replies
12
Views
609
Replies
2
Views
208
Replies
5
Views
570