uniform_int_distribution在这里使用错误? (我的结果似乎不均匀分布) [英] uniform_int_distribution used wrong here? (my results seem not equally distributed)

查看:1270
本文介绍了uniform_int_distribution在这里使用错误? (我的结果似乎不均匀分布)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

版本3 将发电机移动到类中。

Version 3 Moved generator into a class. Is my new random number generation technique correct this time?

template<typename T = int>
    class MyRandomGenerator
    {
    public:
        MyRandomGenerator()
        {
            std::random_device rd;
            gen = std::mt19937{rd()};
        }

        T getNumber(const T& From, const T& To)
        {
            std::uniform_int_distribution<T> dist(From, To);
            return dist(gen);
        }
    private:
        std::mt19937 gen;
    };

在这里我的新位置计算器:

And here my new position calculators:

auto calculate_x_position = [&]() ->sf::Uint32 {return RandGen.getNumber(0, W - 1); };
auto calculate_y_position = [&]() ->sf::Uint32 {return RandGen.getNumber(0, H - 1); };

与前面相同的模式/问题:

Same pattern/problem as before:

版本2 每秒创建〜3张地图每张地图10.000颗星。结果仍然是一样的。此外,它更清楚的是,有一个枢轴到地图的顶部。示例:

Version 2 Creating ~3 maps per second of 10.000 stars per map. The outcome is still the same. Moreover, it gets even more clear that there is a pivot to the top of the maps. Example:

原始问题:
i尝试绘制简单的星空图。为此,我首先计算星星的x和y位置。 X和Y在窗口的宽度和高度范围内。

Original Question: i went into trying to draw a simple star map. For this i first calculate the x and y position for the stars. X and Y are within the range of width and height of the window.

这是我的随机数生成函数:

This is my random number generating function:

    template<typename T>
    T getRandomNumberBetween(const T& Min, const T& Max)
    {
        static std::random_device rd;
        static std::uniform_int_distribution<T> dist{Min, Max};
        return dist(rd);
    }

我这样使用:

auto calculate_x_position = std::bind(inc::getRandomNumberBetween<sf::Uint32>, 0, Width-1);
    auto calculate_y_position = std::bind(inc::getRandomNumberBetween<sf::Uint32>, 0, Height-1);
x = calculate_x_position(); //...

但是当我绘制我的地图一遍又一遍在我看来,是大多数星星倾向于的地方。例如。

But as i draw my map over and over again it seems to me that there is a pivot to where most stars tend to be. E.g. the majority of stars are in the upper half of my window.

例如:

我使用错误或有错误的期望这里?因为这里它说:

Am i using it wrong or having a wrong expectation here?... Because here it says:


此分布在范围[a,b]中生成随机整数,其中每个
可能值具有相等的生成可能性。

This distribution produces random integers in a range [a,b] where each possible value has an equal likelihood of being produced.

种类问题

推荐答案

您将在屏幕的每个象限获得相等的金额;这意味着每个点出现的机会均等。所以,如果你做一个简单的50:50的试验,这并不意味着你会得到50:50的结果。

Uniform distribution does not specifically mean that you will get an equal amount in each quadrant of the screen; It means that there is an equal chance of each point appearing. So if you do a simple 50:50 trial, it does not mean you will get 50:50 results.

但是如果你做了一个测试与说100万颗星很可能它们将几乎均匀分布。对我来说,这似乎是样本大小的错误

However if you did a test with say 1,000,000 stars it is very likely that they will be nearly uniformly distributed. To me this seems like an error in sample size

这篇关于uniform_int_distribution在这里使用错误? (我的结果似乎不均匀分布)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆