How to build random number every loop different?

hello guys
i have a problem when i develop this code when i want to do 400 round and every round i want to get unique random number for choosing cordinat in my project. can anyone help me, thank you
%rnd is round when looping
startx=[];
starty=[];
center=[];
%rng('default');
rng('shuffle');
acak(:,rnd)=randi(n,8,1);
for i=1:k
startx(i)=x(acak(i,rnd));
starty(i)=y(acak(i,rnd));
center(i,1)=startx(i);
center(i,2)=starty(i);
end
velop rng in kmeans algorithm, i want to get random number

Answers (1)

Adam Danz
Adam Danz on 12 Feb 2021
Edited: Adam Danz on 12 Feb 2021
It looks like you want random positive integers without repetition based on your use of randi.
p = randperm(n,k) where n is the maximum interger to choose from and k is the number of random values to pull. Obvious k cannot be greater than n.

Categories

Find more on Random Number Generation in Help Center and File Exchange

Asked:

on 12 Feb 2021

Edited:

on 12 Feb 2021

Community Treasure Hunt

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

Start Hunting!