【问题标题】:Monty Hall paradox - randomly generated number different from the previous two蒙蒂霍尔悖论 - 随机生成的数字与前两个不同
【发布时间】:2014-04-03 11:12:23
【问题描述】:

我正在编写一个脚本来在 MATLAB 中证明蒙蒂霍尔悖论,但我遇到了一个问题 - 不知道怎么让MATLAB生成一个和前面两个不同的1到3之间的随机数。

这是我的脚本:

% This program demostrates the Monty Hall paradox.
% A_pick1 represents where person chooses to put the five-pound note
% B_pick1 represents which box person B  first identifies
% A_pick2 represents the box that person A opens up - it must be different
% than both A_pick1 and B_pick2

A_pick1 = round(3 * rand(1) + 0.5)
B_pick1 = round(3 * rand(1) + 0.5)
A_pick2 = round(3* rand(1) + 0.5);
while (A_pick2 == A_pick1 || A_pick2 == B_pick1)
   A_pick2 = rand(3 * rand(1) + 0.5) ~= (A_pick1 && B_pick1)
    break
end

我不确定如何正确使用 while 循环。

提前致谢

【问题讨论】:

    标签: matlab random paradox


    【解决方案1】:

    使用randisetxor 怎么样?

    A_pick1 = randi(3);
    B_pick1 = randi(3);
    
    x = setxor(1:3,[A_pick1, B_pick1]);
    A_pick2 = x(randi(numel(x)));
    

    如果你有统计工具箱,还有其他选择,但我相信这应该做得很好。

    祝你好运!

    【讨论】:

      【解决方案2】:

      试试

      A_pick1 = round(3.0 * rand(1.0) + 0.5)
      

      这样你就可以确保双倍。 也许你想初始化你的随机数生成器rng,就像在rng('shuffle');中一样

      【讨论】:

        【解决方案3】:
        while (A_pick2 == A_pick1 || A_pick2 == B_pick1)
           A_pick2 = rand(3 * rand(1) + 0.5);
        end
        

        【讨论】:

          猜你喜欢
          • 2018-02-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-10-18
          • 2021-09-03
          • 2021-03-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多