Search
 
SCRIPT & CODE EXAMPLE
 

CPP

select one random element of a vector in c++

vector<int> v{10,21,24,13};

int random = rand() % v.size();
int sel_elem = v[random];

cout<<"Selected Element: "<<sel_elem<<endl;
Comment

PREVIOUS NEXT
Code Example
Cpp :: suppress individual warnings in visual c++ 
Cpp :: cpp print vector 
Cpp :: How to make two dimensional string in c++ 
Cpp :: c++ generate random char 
Cpp :: 2d vector print 
Cpp :: how to print the address of an object in c++ 
Cpp :: how to iterate through a map in c++ 
Cpp :: check gpu usage jetson nano 
Cpp :: set platformio to C++17 
Cpp :: rng c++ 
Cpp :: C++ system text format 
Cpp :: for loop vector 
Cpp :: c++ hello world program 
Cpp :: have unique vector after sorting vector 
Cpp :: how to get mouse position on window sfm; 
Cpp :: cpp executing without console 
Cpp :: how to sort a 2d array in c++ 
Cpp :: declare dictionary cpp 
Cpp :: cuda constant memory initialisation 
Cpp :: c++ nodiscard 
Cpp :: cpp random in range 
Cpp :: landscape overleaf 
Cpp :: c++ random number generator uniform distribution 
Cpp :: quotation in c++ string 
Cpp :: convert string to stream c++ 
Cpp :: fork was not declared in this scope 
Cpp :: cpp merge two sets 
Cpp :: opencv c++ hello world 
Cpp :: how to read a comma delimited file into an array c++ 
Cpp :: c++ vector sort 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =