random in c++
#include
#include
#include
using namespace std;
int main()
{
int num;
srand(time(0));
num = rand() % 10 + 1;
cout << num << endl;
}
c++ random
#include
#include
#include
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';
}
how to make a random number in c++
#include
#include
#include
using namespace std;
int main() {
srand(time(NULL) );
const char arrayNum[7] = {'0', '1', '2', '3', '4', '5', '6'};
int RandIndex = rand() % 7;
cout<
rand() c++
v1 = rand() % 100; // v1 in the range 0 to 99 --Credit goes to Clever cowfish
v2 = rand() % 100 + 1; // v2 in the range 1 to 100
v3 = rand() % 30 + 1985; // v3 in the range 1985-2014
c++ random number
#include
#include
using namespace std;
//Generate random numbers
int main(){
srand(time(0));
for (int i = 0; i < 10; i++){
cout<< (rand() % 10) + 1<<" ";
c++ random number
#include
typedef std::mt19937 MyRNG; // the Mersenne Twister with a popular choice of parameters
uint32_t seed_val; // populate somehow
MyRNG rng; // e.g. keep one global instance (per thread)
void initialize()
{
rng.seed(seed_val);
}
int main() {
std::uniform_int_distribution uint_dist; // by default range [0, MAX]
std::uniform_int_distribution uint_dist10(0,10); // range [0,10]
std::normal_distribution normal_dist(mean, stddeviation); // N(mean, stddeviation)
while (true){
std::cout << uint_dist(rng) << " "
<< uint_dist10(rng) << " "
<< normal_dist(rng) << std::endl;
}
}
|