answersLogoWhite

0

Use the random number generator classes.

#include<random>

#include<ctime>

std::default_random_engine generator ((unsigned)time(0)); // seed the generator

std::uniform_int_distribution<int> distribution (0, 100); // set the closed range

int r = distribution (generator); // pick a random number from 0 to 100 (inclusive)

Any device can be used to seed the generator. Here, we've simply used the current time. If you don't seed the generator, it will generate the same sequence of random values every time the program is run.

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

What is randomize function in c plus plus?

You can use rand(). Make sure that you use srand()to generate the seed for rand() (if you do not, you get so called pseudo random numbers).


What is rand function in c plus plus?

The rand() function returns an integer (int) value that represents a pseudo-random number between 0 and RAND_MAX, RAND_MAX being a constant declared in the run-time library. Each time rand() is invoked, a different value is returned.


How do you calculate the size of a class in memory in C plus plus?

Use sizeof( ).


What has the author Marguerite C Rand written?

Marguerite C. Rand has written: 'Ramo n Pe rez de Ayala'


How do you calculate percentage of marks obtained in 1 subject in c plus plus?

You can't, you have to come up with variables to calculate grades


Can anyone give you the c plus plus code to check where the line ax plus by plus c cuts the circle x2 plus y2 plus 2gx plus 2fy plus c equals 0 where a b c g f are entered by the user?

Your question is not clear. Please give the formula to calculate the value of x and the condition at which the line cuts the circle


C plus plus program calculate the power value of input base and exponent numbers?

cn = c0 *( 1 + i ) pow n


What has the author Neill C Ostrander written?

Neill C. Ostrander has written: 'The Rand Sync-Sat Calculator' -- subject(s): Rand Sync-Sat Calculator, Syncom (Communications satellite)


Can anyone give a code for c plus plus to do a random dice roll for a dropped item when a crate is destroyed?

int die = ((double)rand())*6/RAND_MAX+1; // result is 1, 2, 3, 4, 5, or 6


How do you calculate formula for a plus b plus c plus d equals 12 when a equals b plus c and c equals d?

There are four unknown variables and only three linear equations so there is not a unique solution. All you can do is to rearrange the four variables so that three of them can be expressed in terms of the fourth. For example: In terms of c, a = 6 - c/2 b = a - c = 6 - 3c/2 d = c


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c