MATLAB Answers

Kobi
0

values of randi function repeat themselves

Asked by Kobi
on 30 Aug 2014
Latest activity Edited by Kobi
on 1 Sep 2014
while using the function randi that generate random integers uniformly disterbuted i sometimes get in the output vector the same numbers for example:
4 2 5 3 4 8 7 9 7 4
(the number 4 was three times in the row above)
how can i avoid this?
locTX=randi([1 20],1,4);

  0 Comments

Sign in to comment.

1 Answer

Answer by Azzi Abdelmalek
on 30 Aug 2014
Edited by Azzi Abdelmalek
on 30 Aug 2014
 Accepted Answer

Use randperm function

  4 Comments

Show 1 older comment
Each number occurs exactly once. The numbers themselves are not random. They go from 1 up to some numbers, including every integer in between. Only the location of the numbers is random. So even if you scramble their location, each number still appears only once. By the way, there is no function called randni().
i use randi not randni
about the other quastion how does the random numbers distributed? uniformly?
rand() and randi() are uniform. randn() is normally/Gaussian distributed. You might want to edit your post (body and subject line) to get rid of randni to avoid confusing people with a function that you say you don't use.

Sign in to comment.