December 2015
Beginner to intermediate
522 pages
11h 21m
English
A fairly common thing people often forget is the following line:
srand(time(nullptr));
If you notice, the numbers being generated are exactly the same each time you launch the game-chances are that you haven't seeded the random number generator or you haven't provided a proper seed. It's recommended to always use a unix timestamp, as shown.
The use of this particular random function should be restricted to something that isn't related to security and cryptography. Using it in combination with the modulus operator can produce incredibly non-uniform results due to the introduced bias.
Another fairly common problem is the programmers' choice of the data container to hold their structures. Let's take the following for example:
using ...
Read now
Unlock full access