January 2016
Intermediate to advanced
304 pages
6h 17m
English
Perhaps the simplest of all data types is the humble bool. With only two states, true and false, it shouldn't be too hard to set randomly! When represented as integers, the two states have the following properties:
Given this, to randomly assign a bool we simply need to generate either the number 0 or 1.
In Chapter 1, An Introduction to Procedural Generation, we covered the generation of random numbers within a specific range. Well we're now going to put that to use. Using the std::rand() function we will generate a number between 0 and 1:
std::rand() % 2;
Remember, std::rand() generates a number between 0 and RAND_MAX function. We then calculate ...
Read now
Unlock full access