generate random numbers in range from (0.8 to 4)
231 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jamal Ahmad
el 11 de Mzo. de 2013
Comentada: Image Analyst
el 20 de En. de 2021
Hi How to generate 20 random numbers in range from (0.8 to 4) Thanks
1 comentario
Respuesta aceptada
Azzi Abdelmalek
el 11 de Mzo. de 2013
Editada: Azzi Abdelmalek
el 11 de Mzo. de 2013
xmin=0.8
xmax=4
n=20
x=xmin+rand(1,n)*(xmax-xmin)
3 comentarios
Steven Lord
el 19 de En. de 2021
xmin=0.8;
xmax=4;
n = 1e6; % Generating a few more numbers than the original n=20;
x=xmin+rand(1,n)*(xmax-xmin);
histogram(x, 0.8:0.1:4.1)
Looks reasonably uniform to me.
Image Analyst
el 20 de En. de 2021
If you want it EXACTLY perfectly uniform (which is doubtful), then you should use linspace() instead of rand().
Más respuestas (3)
Image Analyst
el 11 de Mzo. de 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 comentario
Ka Mirul
el 17 de Oct. de 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 comentarios
Ver también
Categorías
Más información sobre Random Number Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!