random number generator c++
C++
v1 = rand() % 100; // v1 in the range 0 to 99
v2 = rand() % 100 + 1; // v2 in the range 1 to 100
v3 = rand() % 30 + 1985; // v3 in the range 1985-2014 /* rand example: guess the number */
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
int main ()
{
int iSecret, iGuess;
/* initialize random seed: */
srand (time(NULL));
/* generate secret number between 1 and 10: */
iSecret = rand() % 10 + 1;
do {
printf ("Guess the number (1 to 10): ");
scanf ("%d",&iGuess);
if (iSecret<iGuess) puts ("The secret number is lower");
else if (iSecret>iGuess) puts ("The secret number is higher");
} while (iSecret!=iGuess);
puts ("Congratulations!");
return 0;
}#include <cstdlib>
#include <iostream>
#include <ctime>
int main()
{
std::srand(std::time(nullptr)); // use current time as seed for random generator
int random_variable = std::rand();
std::cout << "Random value on [0 " << RAND_MAX << "]: "
<< random_variable << '\n';
}
Also in C++:
- Title
- copy a part of a vector in another in c++
- Category
- C++
- Title
- declaring iterator in cpp
- Category
- C++
- Title
- nginx linux
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- how long can a c++ string be
- Category
- C++
- Title
- gcd in c++
- Category
- C++
- Title
- howt o initialize 3d vector in c++
- Category
- C++
- Title
- getline in c++
- Category
- C++
- Title
- if vector contains value c++
- Category
- C++
- Title
- how to initialize an struct object in c++
- Category
- C++
- Title
- what does map.count() return in c++
- Category
- C++
- Title
- c++ do while loop
- Category
- C++
- Title
- stringstream in c++
- Category
- C++
- Title
- pass vector by reference c++
- Category
- C++
- Title
- FInd the element which appears more than n/2 times C++
- Category
- C++
- Title
- object reference not set to an instance of an object c#
- Category
- C++
- Title
- c++ clear console
- Category
- C++
- Title
- memset
- Category
- C++
- Title
- c++ function return array
- Category
- C++
- Title
- c++ movment
- Category
- C++
- Title
- make an x using asterisk c++
- Category
- C++
- Title
- what is meaning of 64 bit integer in c++
- Category
- C++
- Title
- c++ char to int
- Category
- C++
- Title
- how to compare lower case character to uppercase cpp
- Category
- C++
- Title
- c++ main function
- Category
- C++
- Title
- c++ function to find minimum element in array
- Category
- C++
- Title
- c++ lettura file
- Category
- C++
- Title
- substitution failure is not an error
- Category
- C++
- Title
- & in xml
- Category
- C++
- Title
- passing array to function c++ pointer
- Category
- C++
- Title
- how to round to nearest whole number unity
- Category
- C++
- Title
- traverse map c++
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- c++ ternary operator
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- map vs unordered_map in C++
- Category
- C++
- Title
- variant hold type
- Category
- C++
- Title
- regexp_like oracle c++
- Category
- C++
- Title
- how to cout in c++
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- how to have a queue as a parameter in c++
- Category
- C++
- Title
- solve linear equations geeksforgeeks
- Category
- C++
- Title
- find in set of pairs using first value cpp
- Category
- C++
- Title
- factorion
- Category
- C++
- Title
- power in c++
- Category
- C++
- Title
- c++ for loop
- Category
- C++
- Title
- arduino falling edge
- Category
- C++
- Title
- sub string of vector c++
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- best fit algorithm
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- primeros numeors primos menores que
- Category
- C++
- Title
- pointer related problems dangling/wild pointers c++
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- max three values c++
- Category
- C++
- Title
- c++ loop through int array
- Category
- C++
- Title
- c++ empty stream
- Category
- C++
- Title
- ceil c++;
- Category
- C++
- Title
- how to print a string to console in c++
- Category
- C++
- Title
- 2927260.eps 2927262.jpg 2927263.ai License free.txt License premium.txt
- Category
- C++
- Title
- double to string c++
- Category
- C++
- Title
- self in c++
- Category
- C++
- Title
- new in c++
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- how to check datatype of a variable in c++
- Category
- C++
- Title
- subarray sum in c++
- Category
- C++
- Title
- stack function in cpp
- Category
- C++
- Title
- c++ scanf
- Category
- C++
- Title
- namespace file linking c++
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- reverse in vector c++
- Category
- C++
- Title
- map insert c++
- Category
- C++
- Title
- c++ uint32_t
- Category
- C++
- Title
- border radius layout android xml
- Category
- C++
- Title
- clear file before writing c++
- Category
- C++
- Title
- #include
- Category
- C++
- Title
- remove element by index from vector c++
- Category
- C++
- Title
- c++ string to integer without stoi
- Category
- C++
- Title
- ue4 c++ struct
- Category
- C++
- Title
- c++ give options
- Category
- C++
- Title
- in c, is class uppercase or lowercase
- Category
- C++
- Title
- converting char to int in c++
- Category
- C++
- Title
- mysqli connect
- Category
- C++
- Title
- kruskal's algorithm c++ hackerearth
- Category
- C++
- Title
- two elements with difference K in c++
- Category
- C++
- Title
- ue4 c++ enum
- Category
- C++
- Title
- namespace c++
- Category
- C++
- Title
- array<string, 7> c++
- Category
- C++
- Title
- How to read a file in in C++
- Category
- C++
- Title
- Rectangle area hackerrank solution in c++
- Category
- C++
- Title
- c++ char print width
- Category
- C++
- Title
- c++ initialize a vector
- Category
- C++
- Title
- c++ loop through array
- Category
- C++
- Title
- swapo algorit
- Category
- C++
- Title
- making random numbers in c++
- Category
- C++
- Title
- how to ensure the user inouts a int and not anything else c++
- Category
- C++