Generating random numbers question

2 views (last 30 days)
Nathan
Nathan on 15 Sep 2013
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!

Answers (1)

Image Analyst
Image Analyst on 15 Sep 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 Comments
Image Analyst
Image Analyst on 16 Sep 2013
Edited: Image Analyst on 16 Sep 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 on 16 Sep 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?

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!