G'day!

I found quite some information about random number generators, but I was wondering how to do that with strings.
Here's what I want: I have a list of names (array) and I want to randomize/shuffle them. Then the randomized/shuffled names should be put into 3 groups (new lists).
The output should look like this:
group1: name1, name2, name3
group2: name6, name5, name4
group3: name8, name7, name9

Thanks for helping me out! :

What determines which group a name is placed into?

The names should be randomly placed into the 3 groups.

	var names: Array = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]
	print_debug("names (initial)=", names)
	names.shuffle()
	print_debug("names (shuffled)=", names)
	var group1: Array = []
	var group2: Array = []
	var group3: Array = []
	for n in names:
		match randi() % 3:
			0: group1.append(n)
			1: group2.append(n)
			2: group3.append(n)
	print_debug("group1=", group1)
	print_debug("group2=", group2)
	print_debug("group3=", group3)

That worked well. Thank you!
What if I wanted to make sure that in each group there are at least 3 names?

After creating the groups as above, you could check their sizes, and if any groups have less than three names, move names from another group that has more than three names.

There might be a more optimal way of doing all this.

    9 days later

    DaveTheCoder
    Why the second ranomization?
    You have a random array after the shuffle. Just slice the array into thirds.

    Could you provide an example with what you mean?

    Thx!

    Here's one way:

    var names: Array = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]
    names.shuffle()
    var group1: Array = []
    var group2: Array = []
    var group3: Array = []
    var min_group_size: int = names.size() / 3
    for n in names:
    	if group1.size() < min_group_size:
    		group1.append(n)
    	elif group2.size() < min_group_size:
    		group2.append(n)
    	else:
    	        group3.append(n)

    Ok. This solution is easier to understand for me. Thx so much!

    6 days later