This site works best with JavaScript enabled!

# Description: Random Generator - Form Groups On this page the algorithm of the generator "Form Groups" is described. In this random generator you can enter several names from which groups of the desired size are formed randomly. For example, you can form teams for various games with this generator.

## What is randomness?

Randomness is an event whose state cannot be clearly predicted causally. This means that the result of a random generator may not be predictable or computable. This, however, contradicts the laws of each computer. In other words, a computer can not produce absolutely random numbers without additional peripherals. In this case we call it pseudo-random numbers. In general, you can philosophize about at which point you can actually speak about randomness in practise.

## How are the groups formed?

Theoretically, several different methods are used in this generator to generate pseudo-random values. For the actual answer, a PHP function for cryptographically secure pseudo random numbers is used.

### Random generators for binary string

How these random generators work, is explained here in detail.

### Random generator for group generation

The previous random number generators produce relatively good random numbers, which, however, can further be improved. The groups are therefore always formed on server-side with the PHP function random_int(), which generates cryptographically secure pseudo-random numbers. If the number of groups is given, then the groups are formed as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
```// The array \$names contains all names

// Until all names have been selected
while(\$number_names > 0)
{
// For all groups
for (\$g = 1; (\$g <= \$number_groups) && (\$number_names > 0); \$g++) {
\$index = random_int(0, \$number_names - 1);
\$random_groups[\$g][] = \$names[\$index];
unset(\$names[\$index]);         // Delete entry
\$names = array_values(\$names); // Reset indexes
\$number_names--;
}
}```

If not the number of groups, but the number of persons per group is given, then the algorithm looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
```// The array \$names contains all names

// Until all names have been selected
for (\$g = 1; \$number_names > 0; \$g++) {
// As long as the group is not full
for (\$i = 1; (\$i <= \$number_persons_per_group) && (\$number_names > 0); \$i++)
{
\$index = random_int(0, \$number_names - 1);
\$random_groups[\$g][] = \$names[\$index];
unset(\$names[\$index]);         // Delete entry
\$names = array_values(\$names); // Reset indexes
\$number_names--;
}
}``` 