icdvjnf9700 icdvjnf9700
  • 14-09-2019
  • Computers and Technology
contestada

in c++, what happends when i add 1 to the RAND_MAX then take rand() deivded by (RAND_MAX+1)?if my purpose is to take out a random number within 0=< and =<1?

Respuesta :

ExieFansler ExieFansler
  • 20-09-2019

Explanation:

rand() function is used to generate random integers between the range 0 to RAND_MAX.So if we divide the the rand() function by RAND_MAX the value returned will be 0.

You cannot do RAND_MAX + 1 the compiler will give error integer overflown.

To generate an integer with a range.You have to do like this:

srand(time(0));

int a=-1*(rand() % (0 - 5245621) +1);

cout <<a;

This piece of code will return an integer within the range 0 to -5245622.

Answer Link

Otras preguntas

How are large molecules like carbohydrates moved through the cell membrane?
help asap please and thx
HELLO PLEASE HELP ME OUT!!!! I WILL GIVE BRAINLIEST MARK IF 2 PPL ANSWER For years, China had enjoyed a favorable balance of trade with foreign nations. But the
Which of the following shows the length of the third side, in inches, of the triangle below? A) 20 inches B) √850 inches C) √10 inches D) 40 inches
According to the text, conservatives are people who believe in the widespread use of government power for ______.
How are angles named? (IKR I'm sad)
I caused Friday to gather all the skulls, bones, flesh, and whatever remained
WILL CROWN BRAINLIST!!
Tonya used to smoke a cigarette now and then. In the last few months, she started smoking a lot more cigarettes than she used to. Which consequence is she at ri
Solve the linear system using substitution