在Matlab中,如何生成10个随机种子?

克里斯·珀迪(Kris Purdy)

下面的代码告诉我,我需要使用不同的种子来生成10次随机数,然后对它们进行平均以得到更平滑的图形。我没有使用Matlab的丰富经验,因此即使阅读了文档,我也不了解这些种子的工作原理。

% Create an array
S = 0:20;
CW = 0:5:100;
S(1) = 0;
CW(1) = 0;

counter = 2;  % Counter for the nuber of S 
N = 20;  % Number of nodes

% Collect data for each increment of 5 up to 100 for CW values
for i = 5:5:100

    T = 10000 / i;  % Total number of cycles

    % Create array of next transmission times for N nodes
    transmission_time = floor(i * rng(1, N)); 
    total_success = 0;

    % Loop for T cycles
    for t = 1:T

        % For 0 to the number of contention windows
        for pos = 0:i-1

           % Count the number of nodes that have the current CW
            count = 0;
            for node = 1:N
               if transmission_time(node) == pos
                   count = count + 1;
               end
            end

            % If there is more than 1, then a collision occurs
            collision = false;
            if count > 1
                collision = true;
            % If there is exactly 1, then there is a success
            elseif count == 1
                total_success = total_success + 1;
            end 

            % If there is a collision, reassign new transmissions times
            if collision == true
                for node = 1:N
                    if node == pos
                        transmission_time(node) = floor(i * rand(1));
                    end
                end
            end
        end
    end

    % Display the ratio of successes
    S(counter) = total_success / (T * i);
    counter = counter + 1;
end

% Plot the graph for Success vs CW
plot(CW, S, 'o-');
xlabel('Contention Window, CW');
ylabel('Throughput, S');
克里斯·珀迪(Kris Purdy)

对不起,所有的混乱。我认为你们中的一些人说对了,因为我不需要生成不同的流。

在上面的代码中,有一行显示“ if node == pos”,这是不正确的,应为“ if transmission_time(node)== pos”。

那条线使我的图表变得一团糟。我还需要为成功的数据包生成新的随机数。

谢谢您的所有建议!现在,我对Matlab中的种子如何使用随机性有了更多的了解!

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何为随机数生成随机种子

来自分类Dev

如何创建随机种子

来自分类Dev

在Python中生成随机种子

来自分类Dev

在julia随机数生成器中设置随机种子

来自分类Dev

如何创建随机种子以在每次 simevents 运行时产生不同的结果???(随机种子?)

来自分类Dev

获取随机种子以生成唯一密码

来自分类Dev

如何在python中的sqlalchemy.sql.expression.func.random()中设置随机种子?

来自分类Dev

如何在模块化星系图像仿真工具Galsim中设置随机种子

来自分类Dev

如何在模块化星系图像仿真工具Galsim中设置随机种子

来自分类Dev

什么是随机种子的熵以及它是如何工作的?

来自分类Dev

64位随机种子

来自分类Dev

选择随机种子并保存

来自分类Dev

选择随机种子并保存

来自分类Dev

Z3中使用随机种子

来自分类Dev

Z3中使用随机种子

来自分类Dev

OpenCV随机森林:设置随机种子

来自分类Dev

随机种子之间的区别重要吗?

来自分类Dev

Sympy重新配置随机种子

来自分类Dev

在Rmallet中使用随机种子

来自分类Dev

神经网络超参数调整-设置随机种子是个好主意吗?

来自分类Dev

如何在Windows设备之间使用相同的随机种子?

来自分类Dev

如何为每个对象获取新的Python模块随机种子实例

来自分类Dev

如何为pd.util.testing.makeDataFrame()设置随机种子?

来自分类Dev

如何为dplyr sample_n函数分配随机种子?

来自分类Dev

选择品种邻居时,随机种子无法在NetLogo中重现运行

来自分类Dev

种子在随机数生成中的作用

来自分类Dev

随机播放功能的SystemVerilog数组随机种子

来自分类Dev

NumPy随机种子产生不同的随机数

来自分类Dev

用 ruby 中的一个范围之间的种子生成一个随机数

Related 相关文章

热门标签

归档