Borrar filtros
Borrar filtros

Create a number between specific values

1 visualización (últimos 30 días)
Davidra Fantarina ANDRIAMISAINA
Davidra Fantarina ANDRIAMISAINA el 9 de Mzo. de 2018
Comentada: Jan el 9 de Mzo. de 2018
I want to create a random or not value between specific values:
I have three double a,b,c a>b>c
and i want d number to be (a+c)/2<d<a

Respuesta aceptada

Jan
Jan el 9 de Mzo. de 2018
Editada: Jan el 9 de Mzo. de 2018
A random value between the two limits:
lim1 = (a + c) / 2;
lim2 = a;
d = lim1 + rand * (lim2 - lim1)
  3 comentarios
Walter Roberson
Walter Roberson el 9 de Mzo. de 2018
Yes. rand() can never be exactly 0 or exactly 1, so d can never be exactly lim1 or exactly lim2.
Jan
Jan el 9 de Mzo. de 2018
@Davidra: It is a secure information, if Walter posts it. But you can find this in the documentation of Matlab also: doc rand:
rand returns a single uniformly distributed random number in the
interval (0,1).
The round parentheses mean the open interval without 0.0 and 1.0.

Iniciar sesión para comentar.

Más respuestas (0)

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!

Translated by