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
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...
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,...
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?
An integer N is chosen from 1 to 10 uniformly at random. Two random variables are...
An integer N is chosen from 1 to 10 uniformly at random. Two random variables are defined: X is 1 plus the remainder on division of N by 3. So e.g. when N = 5, the remainder on division by 3 is 2, so X = 3. Y is dN/3e. So e.g. when N = 5, Y = 2. (a) Find E[X], E[Y ] and Var[Y ]. (b) Are X and Y independent?
An integer N is chosen from 1 to 10 uniformly at random. Two random variables are...
An integer N is chosen from 1 to 10 uniformly at random. Two random variables are defined: X is 1 plus the remainder on division of N by 3. So e.g. when N = 5, the remainder on division by 3 is 2, so X = 3. Y is [N/3]. So e.g. when N = 5, Y = 2. (a) Find E[X], E[Y ] and Var[Y ]. (b) Are X and Y independent?
An integer N is chosen from 1 to 10 uniformly at random. Two random variables are...
An integer N is chosen from 1 to 10 uniformly at random. Two random variables are defined: X is 1 plus the remainder on division of N by 3. So e.g. when N = 5, the remainder on division by 3 is 2, so X = 3. Y is [N/3]. So e.g. when N = 5, Y = 2. (a) Find E[X], E[Y ] and Var[Y ]. (b) Are X and Y independent?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT