Q#1: How can the rand() function be constrained to generate random numbers within a specific range?
Answer: The modulus operator (%) can limit the range of generated random numbers. For example, rand() % 6 produces values from 0 to 5. To get numbers from 1 to 6, add 1: rand() % 6 + 1.
Q#2: What does the statement const int arraySize = 100; signify in C++ programming?
Answer: This declares an integer constant arraySize with a value of 100. The const keyword ensures that the value cannot be changed. It is commonly used to define array sizes, allowing easy modification by changing the constant instead of updating multiple occurrences in the code.
Q#3: Why is the null character ('\0') important when working with character arrays in C++?
Answer: The null character marks the end of a string in C++. It allows functions to determine where the string ends, preventing errors when manipulating or printing strings of varying lengths.
Q#4: How can the fairness of a die, rolled millions of times, be tested using the random number generator?
Answer: To test fairness, roll the die millions of times and record the frequency of each number (1–6). If each number appears approximately equally, the die is considered fair. This statistical method evaluates the randomness and fairness of the random number generator.