rand_simple/lib.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
#![doc = include_str!("../README.md")]
mod distributions; // 確率変数の詳細
mod standard_distributions; // 標準分布を計算するモジュール
//#[cfg(test)] mod test_distributions; // 機能確認のためのテストモジュール
#[cfg(test)]
mod sandbox; // 試行錯誤するためのテストモジュール
// 状態変数(x, y, z, u, v)を設定する
// 下記の論文の初期値を参考にする
// https://www.researchgate.net/publication/5142825_Xorshift_RNGs
pub(crate) fn create_state(_seed: u32) -> [u32; 5] {
[123456789, 362436069, 521288629, 88675123, _seed]
}
// 共通処理
#[macro_export]
/// std環境で乱数の種の配列を生成するマクロ
/// * `$length: usize` - 配列の長さ
macro_rules! generate_seeds {
($length: expr) => {{
let mut array = [0_u32; $length];
let duration = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("Time went backwards");
for i in 0..array.len() {
array[i] = match i % 6_usize {
0_usize => duration.as_millis() as u32,
1_usize => std::u32::MAX - duration.as_nanos() as u32,
2_usize => (duration.as_secs() as u32) / 60_u32,
3_usize => std::u32::MAX - duration.as_micros() as u32,
4_usize => duration.as_secs() as u32,
5_usize => (duration.as_millis() as u32) / 60_u32,
_ => 1_192_765_u32,
};
}
array
}};
}
// 配列の要素を互いに異なる値に変更するマクロ
macro_rules! adjust_seeds {
($array:expr) => {{
let mut copy_array = $array;
for i in 0..(copy_array.len() - 1) {
for j in (i + 1)..copy_array.len() {
if copy_array[i] == copy_array[j] {
copy_array[j] = (copy_array[j] << 3) ^ (copy_array[i] >> 2);
if copy_array[j] == 0 {
copy_array[j] = 1192;
}
}
}
}
copy_array
}};
}
pub(crate) use adjust_seeds;
// 連続型確率変数
// 一様乱数
pub use crate::distributions::uniform::Uniform;
// 正規分布
pub use crate::distributions::normal::Normal;
// 半正規分布
pub use crate::distributions::half_normal::HalfNormal;
// 対数正規分布
pub use crate::distributions::log_normal::LogNormal;
// コーシー分布
pub use crate::distributions::cauchy::Cauchy;
// 半コーシー分布
pub use crate::distributions::half_cauchy::HalfCauchy;
// レヴィ分布
pub use crate::distributions::levy::Levy;
// 指数分布
pub use crate::distributions::exponential::Exponential;
// ラプラス分布
pub use crate::distributions::laplace::Laplace;
// 対数ラプラス分布
pub use crate::distributions::log_laplace::LogLaplace;
// レイリー分布
pub use crate::distributions::rayleigh::Rayleigh;
// ワイブル分布
pub use crate::distributions::weibull::Weibull;
// 反射ワイブル分布
pub use crate::distributions::reflected_weibull::ReflectedWeibull;
// フレシェ分布
pub use crate::distributions::frechet::Frechet;
// ガンベル分布
pub use crate::distributions::gunbel::Gunbel;
// ガンマ分布
pub use crate::distributions::gamma::Gamma;
// ベータ分布
pub use crate::distributions::beta::Beta;
// ディリクレ分布
//pub struct Dirichlet {}
// べき関数分布
pub use crate::distributions::power_function::PowerFunction;
// 指数べき分布
//pub struct ExponentialPower {}
// アーラン分布
pub use crate::distributions::erlang::Erlang;
// χ二乗分布
pub use crate::distributions::chi_square::ChiSquare;
// χ分布
pub use crate::distributions::chi::Chi;
// F分布
pub use crate::distributions::f::FDistribution;
// t分布
pub use crate::distributions::t::TDistribution;
// 逆ガウス分布
pub use crate::distributions::inverse_gaussian::InverseGaussian;
// 三角分布
pub use crate::distributions::triangular::Triangular;
// パレート分布
//pub struct Pareto {}
// ロジスティック分布
//pub struct Logistic {}
// 双曲線正割分布
//pub struct HeyperbolicSecant {}
// 余弦分布
//pub struct RaisedCosine {}
// 逆正弦分布
//pub struct Arcsine {}
// フォン・ミーゼス分布
//pub struct VonMises {}
// 非心ガンマ分布
//pub struct NonCentralGamma {}
// 非心ベータ分布
//pub struct NonCentralBeta {}
// 非心ガンマ二乗分布
//pub struct NonCentralChiSquare {}
// 非心ガンマ分布
//pub struct NonCentralChi {}
// 非心F分布
//pub struct NonCentralF {}
// 非心t分布
//pub struct NonCentralT {}
// プランク分布
//pub struct Plank {}
// 離散型確率変数
// ベルヌーイ分布
pub use crate::distributions::bernoulli::Bernoulli;
// 二項分布
//pub struct Binomial {}
// 幾何分布
pub use crate::distributions::geometric::Geometric;
// ポアソン分布
//pub struct Poisson {}
// 超幾何分布
//pub struct HeyperGeometric {}
// 多項分布
//pub struct Multinominal {}
// 負の二項分布
//pub struct NegativeBinomial {}
// 負の超幾何分布
//pub struct NegativeHeyperGeometric {}
// 対数級数分布
//pub struct LogarithmicSeries {}
// ユール・シモン分布
//pub struct YuleSimon {}
// ジップ・マンデルブロート分布
//pub struct ZipfMandelbrot {}
// ゼータ分布
//pub struct Zeta {}