Generating random numbers question

My question involves this assignment:
1. Generate a set of 10,000 random numbers, uniformly distributed between 0 and 100.
I can generate and plot 10000 numbers between 0 and 1 just fine, but Im getting stuck on how to generate between 0 and 100. Ive been using the rand(1) command. Appreciate any help, thanks!

Respuestas (1)

Image Analyst
Image Analyst el 15 de Sept. de 2013
Did you happen to look at the very first example in the help for rand? In case you missed it, here it is:
Example 1:
Generate values from the uniform distribution on the interval [a,b]:
r = a + (b-a).*rand(100,1);
For you, of course, a = 0 and b = 100. And 100 would be 10,000, so it becomes:
r = 100.*rand(10000,1);

3 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 15 de Sept. de 2013
[Nathan commented]
ok thanks. I also had a question on this part: Generate a set of 10,000 normally distributed random numbers with mean of 50 and standard deviation of 20
Im having trouble coding this out while keeping it in the same script as the previous question
Image Analyst
Image Analyst el 16 de Sept. de 2013
Editada: Image Analyst el 16 de Sept. de 2013
There is a randn() function that I'm quite confident you'll have no trouble figuring out. The fact that you are calling rand() earlier in the script is of no consequence. You can use different variable names for each set of random numbers of course. So, what trouble are you having, keeping the two in the same script?
Walter Roberson
Walter Roberson el 16 de Sept. de 2013
Suppose you have a book that is balanced right over the X axis, equal parts to the left and right. Where is the (vertical) mean position of the book? Now suppose you move the book 10 cm to the right. Where is the (vertical) mean position of the book now?

Iniciar sesión para comentar.

Categorías

Más información sobre Random Number Generation en Centro de ayuda y File Exchange.

Preguntada:

el 15 de Sept. de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by