Constraints on randomly generated integers randi

Hi all,
I have the following function that generates random integers between two points:
Int = randi([x1 x2],1,10);
I am trying to find a neat way of generating these integers such that there is no repetition. i.e. I want 10 separate random integers in the answer. The difference between the values of x1 and x2 is large enough to generate separate integers; however, I do find that sometimes I get the same integer twice in the one solution. Any tips?

 Respuesta aceptada

Star Strider
Star Strider el 18 de Oct. de 2017
One approach:
x1 = 5; % Create Limits
x2 = 15; % Create Limits
Out = (x1-1) + randperm(x2-x1+1, 10);

2 comentarios

Thank you this worked well
Star Strider
Star Strider el 18 de Oct. de 2017
As always, my pleasure.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink Design Optimization en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de Oct. de 2017

Comentada:

el 18 de Oct. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by