How do generate random numbers in C++? Provide 2-3 examples and explain what numbers they generate.
Generating random numbers can be used in multiple ways. You are going to have to type the random function in the perimeter you want, the code you have to type is, rand(). and you can restrict the randomness by adding a module and a number to go with the module, it will look like this rand() %700. One example is you can draw a rectangle and put the rand number function in the color parameters and get random colors for the shape each time you run the code or every time the code loops. Another example is putting the rand function in the shapes position and size parameter. Each time you run the code or the code loops, you'll have a random rectangle with a random size and position.
No comments:
Post a Comment