selecting a random value within a specific interval

 Respuesta aceptada

Image Analyst
Image Analyst el 10 de Feb. de 2015
Did you look up rand() in the help? It's one of the examples:
Random Numbers Within Specified Interval
Generate a 10-by-1 column vector of uniformly distributed numbers in the interval [-5,5].
r = -5 + (5+5)*rand(10,1)
r =
3.1472
4.0579
-3.7301
4.1338
1.3236
-4.0246
-2.2150
0.4688
4.5751
4.6489
In general, you can generate N random numbers in the interval [a,b] with the formula r = a + (b-a).*rand(N,1);.

3 comentarios

for normal distribution, it requires other definition.
Guillaume
Guillaume el 10 de Feb. de 2015
Yes, but the OP never mentioned normal, so the assumption is they want a uniform distribution.
If a normal distribution is wanted, use randn(). Other related functions are also found at the bottom of the help in the "See Also" section.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Preguntada:

el 10 de Feb. de 2015

Comentada:

el 10 de Feb. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by