2009年02月12日
正規分布乱数を改善したっす
なぜか「正規分布乱数」で検索して迷い込んでくる方が多いっす。
2か月ちょっと前は投げやりに書いてたっす。
微妙に改善してみたっす。
どうもぺんぎんっす( ◎v◎ )
この前のものと比べてみてくださいっす。
///////////////////////////////
// The MIT Lisenses
// Copyright (c) 2008 Naoya Bellic
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
///////////////////////////////
float BoxMuller()
{
return llSqrt(-2.0 * llLog(1.0 - llFrand(1.0))) * llCos(TWO_PI * (1.0 - llFrand(1.0)));
}
違いは
旧: llFrand(1.0)
新: 1.0 - llFrand(1.0)
ココだけっす。
llFrand(1.0)は[0,1)の範囲っす。
ボックス・ミューラー法で使うのは(0,1]の一様乱数っす。
1.0 - llFrand(1.0)とすることで、この範囲に合わせたっす。
2か月ちょっと前は投げやりに書いてたっす。
微妙に改善してみたっす。
どうもぺんぎんっす( ◎v◎ )
この前のものと比べてみてくださいっす。
///////////////////////////////
// The MIT Lisenses
// Copyright (c) 2008 Naoya Bellic
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
///////////////////////////////
float BoxMuller()
{
return llSqrt(-2.0 * llLog(1.0 - llFrand(1.0))) * llCos(TWO_PI * (1.0 - llFrand(1.0)));
}
違いは
旧: llFrand(1.0)
新: 1.0 - llFrand(1.0)
ココだけっす。
llFrand(1.0)は[0,1)の範囲っす。
ボックス・ミューラー法で使うのは(0,1]の一様乱数っす。
1.0 - llFrand(1.0)とすることで、この範囲に合わせたっす。
例の大会用のオブジェクト、ver0.63になったっすね。
かかった時間を計測してくれる機能も付いてたっす。
自前で処理させようとしてたっすけど、いらなくなったっすね。
便利になったっす。
かかった時間を計測してくれる機能も付いてたっす。
自前で処理させようとしてたっすけど、いらなくなったっすね。
便利になったっす。
Posted by ぺんぎん at 23:00│Comments(0)
│スクリプト