How to build random number every loop different?
Afficher commentaires plus anciens
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
Réponses (1)
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.
Catégories
En savoir plus sur Random Number Generation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!