From 11110e4652bcd7d33826e48175becf9b83e9d254 Mon Sep 17 00:00:00 2001 From: "Chu Chun Yin, Jeremy" <129842660+84ds84d8s@users.noreply.github.com> Date: Tue, 9 Apr 2024 15:43:24 +0800 Subject: [PATCH] Update random_price.cpp --- random_price.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/random_price.cpp b/random_price.cpp index f1ea0d29..043b404d 100644 --- a/random_price.cpp +++ b/random_price.cpp @@ -6,23 +6,15 @@ double init_stock_price(int a) { std::random_device rd; - // Merssane Twister std::mt19937 gen(rd()); + std::normal_distribution distribution(5.0, 2.0); if (a == 2) { - std::normal_distribution distribution(50.0, 20.0); - return distribution(gen); + distribution.param(std::normal_distribution::param_type(50.0, 20.0)); } - else { - if (a == 3) { - std::normal_distribution distribution(150.0, 50.0); - return distribution(gen); - } - else { - std::normal_distribution distribution(5.0, 2.0); - return distribution(gen); - } + if (a == 3) { + distribution.param(std::normal_distribution::param_type(150.0, 50.0)); } - return 0.00; + return distribution(gen); } double random_sd(float price) { std::random_device rd;