The expression double(rand()) / RAND_MAX produces a double-precision random numb
ID: 3646403 • Letter: T
Question
The expression double(rand()) / RAND_MAX produces a double-precision randomnumber between 0.0 and 1.0.
Scaling a random number as an integer value between 0 and N is done with the
expression rand() % (N+1) or int (double(rand())/RAND_MAX * N).
For example, the expression int (double(rand())/RAND_MAX * 100) produces a random
integer between 0 and 100.
To produce a random integer between 1 and N, you can use the expression 1 + rand()
% N.
The more general scaling expression a + rand() % (b + 1 a) can be used to produce a
random integer between the number a and b.
Based on the information above, and post solutions for the following questions 1- 6:
5. Write an expression that creates a double-precision random number in the range
of 0.0 through 500.0.
Explanation / Answer
EXPRESSION : -30 + rand() % (69 + 1 +30)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.