Blame toonz/sources/stdfx/igs_math_random.cpp
|
Toshihiro Shimizu |
890ddd |
#include <limits> /* std::numeric_limits */</limits>
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_math_random.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// using igs::math::random;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
igs::math::random::random() : seed_(1) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 乱数種 seed(0〜std::numeric_limits<long>::max()) */</long>
|
|
Toshihiro Shimizu |
890ddd |
void igs::math::random::seed(unsigned long seed) { this->seed_ = seed; }
|
|
Shinya Kitaoka |
120a6e |
unsigned long igs::math::random::seed(void) const { return this->seed_; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 乱数生成 0〜std::numeric_limits<long>::max() */</long>
|
|
Shinya Kitaoka |
120a6e |
long igs::math::random::next(void) {
|
|
Shinya Kitaoka |
120a6e |
this->seed_ = this->seed_ * 1103515245UL + 12345UL;
|
|
Shinya Kitaoka |
120a6e |
/* 0x41C64E6D + 0x3039 */
|
|
Shinya Kitaoka |
120a6e |
return static_cast<long>(</long>
|
|
Shinya Kitaoka |
120a6e |
(this->seed_) %
|
|
Shinya Kitaoka |
120a6e |
(static_cast<unsigned long="">(std::numeric_limits<long>::max()) + 1UL));</long></unsigned>
|
|
Shinya Kitaoka |
120a6e |
// /* (this->seed_/ 65536)%32768 */
|
|
Shinya Kitaoka |
120a6e |
// return (this->seed_/0x10000)%0x8000;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
double igs::math::random::next_d(void) { /* 0 ... 1 */
|
|
Shinya Kitaoka |
120a6e |
return static_cast<double>(this->next()) /</double>
|
|
Shinya Kitaoka |
120a6e |
static_cast<double>(std::numeric_limits<long>::max());</long></double>
|
|
Toshihiro Shimizu |
890ddd |
}
|