1 changed files with 23 additions and 0 deletions
@ -0,0 +1,23 @@ |
|||||
|
#include <iostream> // Required for input/output operations (e.g., std::cout) |
||||
|
#include <cstdlib> // Required for rand() and srand() functions |
||||
|
#include <ctime> // Required for time() function to seed the random number generator |
||||
|
|
||||
|
|||||
|
int main() { |
||||
hatam
commented 2 weeks ago
Review
Another Comment
hatam
commented 2 weeks ago
Review
Another Comment |
|||||
|
// Seed the random number generator using the current time.
|
||||
|
// This ensures a different sequence of random numbers each time the program runs.
|
||||
|
srand(static_cast<unsigned int>(time(0))); |
||||
|
|
||||
|
// Generate a random number.
|
||||
|
// rand() returns a pseudo-random integer in the range [0, RAND_MAX].
|
||||
|
int randomNumber = rand(); |
||||
|
|
||||
|
// Generate a random number within a specific range (e.g., 0 to 99).
|
||||
|
// The modulo operator (%) is used to limit the range.
|
||||
|
int randomNumberInRange = rand() % 100; |
||||
|
|
||||
|
// Print the generated random numbers.
|
||||
|
std::cout << "A raw random number: " << randomNumber << std::endl; |
||||
|
std::cout << "A random number between 0 and 99: " << randomNumberInRange << std::endl; |
||||
|
|
||||
|
return 0; // Indicate successful program execution
|
||||
|
} |
Loading…
Reference in new issue
A Comment