In the code below, I want to ensure that there is an even chance of theImageRand being equal to theImage or theImage2, but I realized that between 1 and 100 more numbers are equal to 2 mod 1 than 2 mod 0. So theImage is being chosen a disproportionate amount of the time.
This was the simplest idea that came to me, but maybe there is a function that can do this easier? I was also thinking that I could find a number that fits what I'm looking for and put that into randi(n).
xRand = randi(100);
if mod(xRand,2) == 1
theImageRand = theImage;
elseif mod(xRand,2) == 0
theImageRand = theImage2;
end
Please let me know if I can explain more clearly. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire