rand c++
C++
#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';
}// C program to generate random numbers
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
// Driver program
int main(void)
{
// This program will create different sequence of
// random numbers on every program run
// Use current time as seed for random generator
srand(time(0));
for(int i = 0; i<5; i++)
printf(" %d ", rand());
return 0;
}
/* 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;
}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
Also in C++:
- Title
- unordered_map c++ insert
- Category
- C++
- Title
- variadic templates
- Category
- C++
- Title
- hohw toparse a string in c++
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- Insert into vector C++
- Category
- C++
- Title
- mysqli connect
- Category
- C++
- Title
- howt o initialize 3d vector in c++
- Category
- C++
- Title
- for c++
- Category
- C++
- Title
- array sort c++
- Category
- C++
- Title
- iterative preorder traversal
- Category
- C++
- Title
- capitalize first letter c++
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- properties of a set c++
- Category
- C++
- Title
- variabvles in c++
- Category
- C++
- Title
- c++ give options
- Category
- C++
- Title
- Convert binary tree to a doubly linked list
- Category
- C++
- Title
- how to ensure the user inouts a int and not anything else c++
- Category
- C++
- Title
- stack c++
- Category
- C++
- Title
- c++ template function
- Category
- C++
- Title
- caesar cipher program in c++
- Category
- C++
- Title
- c++ transform
- Category
- C++
- Title
- stack function in cpp
- Category
- C++
- Title
- primos menores que
- Category
- C++
- Title
- how to declare a function in c++
- Category
- C++
- Title
- c++ uint32_t
- Category
- C++
- Title
- *min_element in c++
- Category
- C++
- Title
- c++ function return array
- Category
- C++
- Title
- preorder traversal c++
- Category
- C++
- Title
- how to grab all of user input c++
- Category
- C++
- Title
- delete 2d dynamic array c++
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- c++ for loop
- Category
- C++
- Title
- pionter in c++
- Category
- C++
- Title
- C++ Student::Student()
- Category
- C++
- Title
- max in c++
- Category
- C++
- Title
- bitset c++
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- phph date
- Category
- C++
- Title
- new class * [] c++
- Category
- C++
- Title
- error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(s[i] != "b"){
- Category
- C++
- Title
- sub string of vector c++
- Category
- C++
- Title
- c++ program how to let the user choose different game modes
- Category
- C++
- Title
- gcd in c++
- Category
- C++
- Title
- class is replace by structure
- Category
- C++
- Title
- file objects in c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- Create a program that finds the minimum value in these numbers
- Category
- C++
- Title
- compare values within within a vector c++
- Category
- C++
- Title
- cin.ignore
- Category
- C++
- Title
- c++ typeid get type name
- Category
- C++
- Title
- print type cpp
- Category
- C++
- Title
- dynamic 2d array c++
- Category
- C++
- Title
- how to get os name in c++
- Category
- C++
- Title
- traverse a map
- Category
- C++
- Title
- making random numbers in c++
- Category
- C++
- Title
- how to sort a vector in c++
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- how to make string get spaces c++
- Category
- C++
- Title
- c++ how to return an empty vector
- Category
- C++
- Title
- how to switch to another branch in git
- Category
- C++
- Title
- how to load from files C++
- Category
- C++
- Title
- peak in c++
- Category
- C++
- Title
- is not a nonstatic data member or base class of class
- Category
- C++
- Title
- initialize int c++
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- how to run c++ file mingw cmd
- Category
- C++
- Title
- how to sort in descending order c++
- Category
- C++
- Title
- min in vector c++
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- & in xml
- Category
- C++
- Title
- shuffle vector c++
- Category
- C++
- Title
- unordered_set in c++ and ordered set diff
- Category
- C++
- Title
- case label in c++
- Category
- C++
- Title
- what does count function do in hashmap
- Category
- C++
- Title
- how to output text in c++
- Category
- C++
- Title
- what is time complexity of insertion sort
- Category
- C++
- Title
- string input
- Category
- C++
- Title
- delete files c++
- Category
- C++
- Title
- expected initializer before 'isdigit'|
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- decimal to hex cpp
- Category
- C++
- Title
- bfs in C++
- Category
- C++
- Title
- c++ constructor
- Category
- C++
- Title
- fail() in c++
- Category
- C++
- Title
- pause the console c++
- Category
- C++
- Title
- how to decalre a string in c++
- Category
- C++
- Title
- set of vectors c++
- Category
- C++
- Title
- sort function in cpp
- Category
- C++
- Title
- c++ multiple inheritance diamond problem
- Category
- C++
- Title
- C++ If
- Category
- C++
- Title
- C++ Syntax
- Category
- C++
- Title
- c++ allocate dynamic with initial values
- Category
- C++
- Title
- how to get last element of set in c++
- Category
- C++
- Title
- centos7 mlock2
- Category
- C++
- Title
- insert elements in array in c++11
- Category
- C++
- Title
- C++ cin cout
- Category
- C++
- Title
- c++ vector pop_back
- Category
- C++
- Title
- declaring 2d vector in c++
- Category
- C++