Random number generator sometimes broken

Here are all the villagers that a popular streamer had at 17 minutes into a ranked RM 1v1 ladder game. Notice anything weird?

Game information

  • Version: 101.102.33868.0 (#99404) 12936891
  • Platform: Stream
  • Operating System: Windows 11

Issue

Sometimes in the first part of a multiplayer game, all the things that are supposed to be random seem to be giving very predictable results. All the villagers are born with the same sex, and all the birds cluster in one place.

The birds can be a distraction for players (I saw a pro streamer get really annoyed at them one time). Also, randomness plays a role in arrow mechanics, animal movement, and monk conversions. If the villager ### is not random, I think it’s quite likely that those other mechanics are broken as well during that time period.

Below I have attached a replay where you can see the bug in action. In the first 17 minutes, the players spawned a combined total of 64 villagers from their TCs, and every one was male. (Note that 4 of the starting villagers were female.) With a working random number generator, the odds of this happening are extremely low: you’d expect it to happen once every 2^64 games, which is 36,893,488,147,419,103,232 games. If you add the fact that the birds were all clustered in one place, the odds of this game being the result of a working random number generator get astronomically lower.

(The issue does seem to fix itself at 17:22 in the replay.)

Frequency

This happens less than 25% of the matches I play (RARELY).

Reproduction steps

I don’t know how to reproduce it reliably in a new game, but you can take the replay file I’ve given you, fast forward to 17 minutes, and note the ### of the villagers and the location of the birds.

Expected result

Villagers should have an equal chance of being male or female, and the birds should fly around the map instead of just going to one place.

Image

Here are some screenshots from the attached recorded game.

Birds all in one place:

image

Survivalist’s villagers, all men except for 2 of the starting vills:

MORG_11’s villagers, all men except for 2 of the starting vills:

Recorded game

terrible_rng_17mins.aoe2record (1.4 MB)

Comment

You can implement a single-threaded pseudo-random number generator in about 3 lines of C. The RNG from Newlib basically boils down to this C code:

uint64_t seed = ...;

int rand()
{
  seed = seed * 6364136223846793005 + 1;
  return seed >> 32 & 0x7FFFFFFF;
}

If there’s some bug and you don’t seed this random number generator, the first random value will be 0, but then after that it will immediately start giving numbers that at least look random even if they aren’t.

A similar bug was reported 3 years ago but the documentation was lacking.

2 Likes

Maybe you can fix the automatic censoring on this forum as well. When I try to use the phrase “villager gender” except I replace the second word with the three-letter word starting with S and ending with X, with an E in the middle, it censors me for no reason. Then it also censors the recorded game that I uploaded, lol. I have to edit the post to get the recorded game back in.

Your forum has apparently decided that the random sequence of letters and numbers it assigned to my replay upload is a bad word, and censors it if I try to paste it here: ############################

1 Like

This has happened to me before, I trained about 30 vils in Return of Rome and none of them were female.

1 Like

I fail to identify the issue. We dont need females or birds.

In the first 17 minutes, the players spawned a combined total of 64 villagers from their TCs, and every one was male. (Note that 4 of the starting villagers were female.) With a working random number generator, the odds of this happening are extremely low: you’d expect it to happen once every 2^64 games

Just a nitpick but that’s the probability of any “chain” of 64 villagers to be all of the same sex, not a probability per game.

The team is aware of this issue, thanks for the report.