Question

I don't understand something Why Math.floor(Math.random() * 10) + 1; returns a random integer from 1...

I don't understand something Why Math.floor(Math.random() * 10) + 1; returns a random integer from 1 to 10? and  Math.floor(Math.random() * 11);   returns a random integer from 0 to 10 not 11?    Math.floor(Math.random() * 10) + 5 gives you a number like 12?   Why they are different from each other and they have the same attribute?

Is there a formula for that, I want a full explanation please?

Homework Answers

Answer #1

Math.random() will generate a random number between 0 to 1 so if we multiply with 10 it will random number between 0-9.9999 so if if we do floor() than it will random number between 0-9

in first case Math.floor(Math.random() * 10) + 1

here you will get random numbers from 1-10 because Math.floor(Math.random() * 10) will give you 0-9 for that your adding 1 so it will be 1-10

Math.floor(Math.random() * 11); it will gie 0-10.999 as your using floor it will make 1-10 only and your not adding +1 here if you add you will get 1-11

Math.floor(Math.random() * 10) + 5: here you wll get 5-14

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Why is the formula for time of flight of a projectile T=2vsin(Theta)/g? I don't understand where...
Why is the formula for time of flight of a projectile T=2vsin(Theta)/g? I don't understand where the 2 comes from.
Hello.. *Please, i need Unique answer (don't copy and paste). *Please, don't use handwriting. *Please i...
Hello.. *Please, i need Unique answer (don't copy and paste). *Please, don't use handwriting. *Please i need Reference Like: URL Link.. _______ Book: Introduction to Anatomy and physiology * Help me, Answer all Questions, and I need more details and more Explain ____________ Q: In your dream, you are floating on a raft in the middle of the ocean. The sun’s hot, you are very thirsty, and you are surrounded by water. You want to take a long, cool drink...
I don't understand the difference between these two problems. Problem #1 has you 4 P 4...
I don't understand the difference between these two problems. Problem #1 has you 4 P 4 / 4 = 4!/4 because I guess you can rotate it 4 times and it'd still be in the same arrangements as each of those women still have the same neighbors during those 4 rotations. Please correct me if I am wrong. However, in Problem #2, this time has 3 boys and 4 girls sitting at a circular table, to which boys have to...
Hello.. *Please, i need Unique answer (don't copy and paste). *Please, don't use handwriting. *Please i...
Hello.. *Please, i need Unique answer (don't copy and paste). *Please, don't use handwriting. *Please i need Reference Like: URL Link.. _______ Book: Introduction to Anatomy and physiology * Help me, Answer all Questions, and I need more details and more Explain ____________ Q: In your dream, you are floating on a raft in the middle of the ocean. The sun’s hot, you are very thirsty, and you are surrounded by water. You want to take a long, cool drink...
Hello.. *Please, i need Unique answer (don't copy and paste). *Please, don't use handwriting. *Please i...
Hello.. *Please, i need Unique answer (don't copy and paste). *Please, don't use handwriting. *Please i need Reference Like: URL Link.. _______ Book: Introduction to Anatomy and physiology * Help me, Answer all Questions, and I need more details and more Explain ____________ Q: In your dream, you are floating on a raft in the middle of the ocean. The sun’s hot, you are very thirsty, and you are surrounded by water. You want to take a long, cool drink...
How do you convert 54 from base 10 to base 2. (I don't get the question...
How do you convert 54 from base 10 to base 2. (I don't get the question and need step by step explanation, please.)
Solve using periodic properties: Sin-1(sin(5π/8)) cos (16π/3) Assuming you don't have a calculator to check your...
Solve using periodic properties: Sin-1(sin(5π/8)) cos (16π/3) Assuming you don't have a calculator to check your work, I don't understand how to find the corresponding angle on the periodic circle. I really need a detailed explanation. I understand the math so I don't need someone showing me how to subtract 5π-2π =3π, but more so how you would know how to subtract 5-2 as opposed to 5π-4π to get π/8? I've seen people solve many questions like these different ways,...
I need explanation on this questions. I saw the answers. But I don't understand how to...
I need explanation on this questions. I saw the answers. But I don't understand how to do these. Please explain. On January 1, 20X4, Passive Heating Corporation paid $104,000 for $100,000 par value, 9 percent bonds of Solar Energy Corporation. Solar had issued $300,000 of the 10-year bonds on January 1, 20X2, for $360,000. The bonds pay interest semiannually. Passive previously had purchased 80 percent of the common stock of Solar on January 1, 20X1, at underlying book value. Passive...
please I don't really know how to start answering this question I really need to understand...
please I don't really know how to start answering this question I really need to understand it please and please show the steps and the work with a clear handwriting thank you very much Canine projectile 1- A dog leaps off the ground to try to clear a fence that is 1.5 m high. The dog launches herself at an angle of 45◦ and a speed of 10 ms−1. She jumps from a distance 2 m away from the fence....
Suppose that a random odd integer p is chosen from {1, … , 2^1024} and p...
Suppose that a random odd integer p is chosen from {1, … , 2^1024} and p passes Miller’s test for 10 different values of a. What is the probability that p is prime?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT