I have a program like this (MATLAB function on Simulink): And I want it to stop when I get 256 values. Does the randi function work almost continuously?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
function [ key ] = keyGen()
key = zeros(1,256);
for i = 1:256
if(rem(i,9)==0)
key(i) = i;
else
x = 261;
while rem(x,9) == 0 || ~isempty(find(key == x, 1)) || i == x
x = randi([1,256]);
end
key(i) = x;
end
end
end
1 comentario
Jan
el 5 de Mzo. de 2022
I do not understand the question. randi does not work continously, but randomly.
Respuestas (1)
Benjamin Thompson
el 7 de Mzo. de 2022
You can call randi once to get a set of integer random numbers as a vector or matrix. Call randi(N, X, Y), where N is the max integer value that you want randi to return, X is the number of rows in the output, Y is the number of columns in the output.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!