MATLAB Answers

generate random numbers in range from (0.8 to 4)

1.836 views (last 30 days)
Jamal Ahmad
Jamal Ahmad on 11 Mar 2013
Edited: Jan on 6 Nov 2017
Hi How to generate 20 random numbers in range from (0.8 to 4) Thanks

  1 Comment

Jan
Jan on 6 Nov 2017
@Arnab: See Azzi's and Image Analyst's answers, which contains exactly the same.

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 11 Mar 2013
Edited: Azzi Abdelmalek on 11 Mar 2013
xmin=0.8
xmax=4
n=20
x=xmin+rand(1,n)*(xmax-xmin)

  0 Comments

Sign in to comment.

More Answers (3)

Image Analyst
Image Analyst on 11 Mar 2013
Did you look in the help? You will see the first example does what you want:
Example 1
Generate values from the uniform distribution on the interval [a, b]:
r = a + (b-a).*rand(100,1);

  1 Comment

Jan
Jan on 11 Mar 2013
Suggesting to read the help text is a very strong idea, because it helps in nearly all future problems also.

Sign in to comment.


ChristianW
ChristianW on 11 Mar 2013
n = 20;
R = [0.8 4];
z = rand(n,1)*range(R)+min(R)

  0 Comments

Sign in to comment.


Ka Mirul
Ka Mirul on 17 Oct 2017

Hallo, I have seen a tutorial about "Generating Random Number in Specific Range" at https://www.youtube.com/watch?v=MyH3-ONYL_k and it works. Hope it will help you.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by