ユニット球面上のランダムな点を選んでいますが、これが正確に行う分布をブーストが提供することがわかりました。しかし、私がそれを使用しようとすると、生成される値はすべてnan
です。私は何が間違っているのか分からない、私を啓発してもらえますか?この小さなコードは、私が何をしようとしています何を表していますboost :: uniform_on_sphereの使い方は?
#include <iostream>
#include <fstream>
#include <vector>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_on_sphere.hpp>
int main()
{
boost::mt19937 gen;
boost::uniform_on_sphere<float> dist(3);
{ // Seed from system random device
std::ifstream rand_device("/dev/urandom");
uint32_t seed;
rand_device >> seed;
gen.seed(seed);
}
while(1) {
// Generate a point on a unit sphere
std::vector<float> res = dist(gen);
// Print the coordinates
for(int i = 0; i < res.size(); ++i) {
std::cout << res[i] << ' ';
}
std::cout << '\n';
}
}
出力は次のようになります。
nan nan nan
nan nan nan
nan nan nan
nan nan nan
無限に
...
コードは(無限ループせずにブースト1.48、そしてもちろんを使用して)私のために正常に動作します。私はそのブーストのあなたのバージョンのバグだと思う。 –