[討論] 關於邏輯運算的一個小問題
各位好我是自學MATLAB新手,
有個小問題想請教大家。
例如大樂透49取6的程式碼如下:
x1 = round(rand*48)+1;
x2 = round(rand*48)+1;
x3 = round(rand*48)+1;
x4 = round(rand*48)+1;
x5 = round(rand*48)+1;
x6 = round(rand*48)+1;
x=[x1 x2 x3 x4 x5 x6];
if(x1~=x2)&(x1~=x3)&(x1~=x4)&(x1~=x5)&(x1~=x6)&(x2~=x3)&(x2~=x4)&(x2~=x5)&(x2~=x6)&
(x3~=x4)&(x3~=x5)&(x3~=x6)&(x4~=x5)&(x4~=x6)&(x5~=x6)
x
end
假如6個亂數產生的號碼真的有重複,
那是否會直接跳出if而沒有東西產生呢?
該如何讓它重run至產生6個不重複數字為止?
抑或是MATLAB本來就會直接重新選亂數直到if式成立為止?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.0.109
推
11/06 16:34, , 1F
11/06 16:34, 1F
→
11/06 23:59, , 2F
11/06 23:59, 2F
推
11/07 00:23, , 3F
11/07 00:23, 3F