Borrar filtros
Borrar filtros

random no.

2 visualizaciones (últimos 30 días)
huda nawaf
huda nawaf el 18 de Mzo. de 2012
hi, can i get random no. in specific range ?
between 19 , -19
thanks
  1 comentario
Oleg Komarov
Oleg Komarov el 18 de Mzo. de 2012
Yes, you can.

Iniciar sesión para comentar.

Respuestas (4)

Image Analyst
Image Analyst el 18 de Mzo. de 2012
You didn't read the help on rand(), did you? If you had, you would have seen the answer to your question as the very first example:
Example 1
Generate values from the uniform distribution on the interval [a, b]:
r = a + (b-a).*rand(100,1);
Needless to say, a=-19 and b = 19 in your case, and 100 is the number of random numbers to be generated, or:
r = -19 + 38 .* rand(100, 1);
  1 comentario
Jan
Jan el 18 de Mzo. de 2012
While the solution in easy, not to say trivial, the suggestion to read the documentation is an will be valuable. +1

Iniciar sesión para comentar.


the cyclist
the cyclist el 18 de Mzo. de 2012
Depending on whether you want to draw from a discrete or a continuous distribution, you will likely want to use either the randi() or unifrnd() function.

Sean Lawson
Sean Lawson el 18 de Mzo. de 2012
naively, this works: 38*(rand-0.5)

Sahyadri Vibhu
Sahyadri Vibhu el 20 de Mzo. de 2012
As Sean Lawson said in the above comment, using -19+38*rand will generate a random real number in the range (-19 19)
to generate random integers use
randi ([lower_limit upper_limit],a,b,c...)
which generates an axbxcx..... random integer array in the range (lower_limit upper_limit)

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by