How to generate the random number with restrictions?

2 visualizaciones (últimos 30 días)
Raja R
Raja R el 7 de En. de 2016
Comentada: Raja R el 8 de En. de 2016
For [1 2 3 ........35], I want to generate random number but the restriction is i want random numbers from [1 2 3...28] as [1 5 9 13 17 21 25] and then after any random number from [29 30 ...35] as normal.

Respuesta aceptada

Guillaume
Guillaume el 7 de En. de 2016
Editada: Guillaume el 7 de En. de 2016
Your question is not very clear, what is a random number "as normal"?
Anyway, to get random numbers from a specific pool of numbers, generate random indices that you use to pick numbers from the pool:
pool = 1:4:25; %pool of numbers pick
numbers = pool(randi(numel(pool), 1, 28)) %choose 28 values from the pool at random.

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 7 de En. de 2016
a1 = 1:28
a2 = 29:35
out = [a1(randperm(numel(a1),7)),a2(randi(numel(a2)))]

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