From 88e26a647819a0bdd18230c960f27eac846d0705 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 29 Mar 2021 11:43:14 +0200 Subject: [PATCH] Fix a few issues with the math class. --- 02_math_osztaly.txt | 6 +++--- 02_math_osztaly/math.cpp | 10 +++++----- 03_monopoly/math.cpp | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/02_math_osztaly.txt b/02_math_osztaly.txt index baa531d..266cbc8 100644 --- a/02_math_osztaly.txt +++ b/02_math_osztaly.txt @@ -147,9 +147,9 @@ UML: | + seed(s : unsigned int) { static } | -> srand(s); | + randomize() { static } | -> srand(time(NULL)); | | -| + rand() : int { static } | -> return rand(); -| + randf() : float { static } | -> return rand() / static_cast(RANDOM_32BIT_MAX); -| + randd() : double { static } | -> return rand() / static_cast(RANDOM_32BIT_MAX); +| + rand() : int { static } | -> return ::rand(); +| + randf() : float { static } | -> return ::rand() / static_cast(RANDOM_32BIT_MAX); +| + randd() : double { static } | -> return ::rand() / static_cast(RANDOM_32BIT_MAX); | | | + rand(int m) : int { static } | -> return rand() % m; | | diff --git a/02_math_osztaly/math.cpp b/02_math_osztaly/math.cpp index 03106a3..9bb5581 100644 --- a/02_math_osztaly/math.cpp +++ b/02_math_osztaly/math.cpp @@ -44,22 +44,22 @@ void Math::randomize() { } int Math::rand() { - return rand(); + return ::rand(); } float Math::randf() { - return rand() / static_cast(RANDOM_32BIT_MAX); + return ::rand() / static_cast(RANDOM_32BIT_MAX); } double Math::randd() { - return rand() / static_cast(RANDOM_32BIT_MAX); + return ::rand() / static_cast(RANDOM_32BIT_MAX); } -int rand(const int m) { +int Math::rand(const int m) { return rand() % m; } -int rand(const int from, const int to) { +int Math::rand(const int from, const int to) { return (rand() % (to - from)) + from; } diff --git a/03_monopoly/math.cpp b/03_monopoly/math.cpp index 03106a3..9bb5581 100644 --- a/03_monopoly/math.cpp +++ b/03_monopoly/math.cpp @@ -44,22 +44,22 @@ void Math::randomize() { } int Math::rand() { - return rand(); + return ::rand(); } float Math::randf() { - return rand() / static_cast(RANDOM_32BIT_MAX); + return ::rand() / static_cast(RANDOM_32BIT_MAX); } double Math::randd() { - return rand() / static_cast(RANDOM_32BIT_MAX); + return ::rand() / static_cast(RANDOM_32BIT_MAX); } -int rand(const int m) { +int Math::rand(const int m) { return rand() % m; } -int rand(const int from, const int to) { +int Math::rand(const int from, const int to) { return (rand() % (to - from)) + from; }