summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjdflyer <jdflyer10@gmail.com>2021-07-10 10:14:53 -0700
committerjdflyer <jdflyer10@gmail.com>2021-07-10 10:14:53 -0700
commit53a9bb6ebee0070a7dc03dd53bc3ab5bbf69b11b (patch)
tree738a5e5a8e600c11191fe76df5e4e3882c1e8b90
parent2ed1ff35280225e76964327d28588484991a64a8 (diff)
Add getRandom to tools
-rw-r--r--include/tools.h8
-rw-r--r--source/tools.cpp8
2 files changed, 16 insertions, 0 deletions
diff --git a/include/tools.h b/include/tools.h
index 5855374..78dd683 100644
--- a/include/tools.h
+++ b/include/tools.h
@@ -53,4 +53,12 @@ namespace libtp::tools
* @return One of the CARD_RESULT Constants (CARD_RESULT_READY, ...)
*/
int32_t ReadGCI( int32_t chan, const char* fileName, int32_t length, int32_t offset, void* buffer );
+
+ /**
+ * @brief Generates a random number based on a seed and a maximum number
+ *
+ * @param seed A reference to the seed that's being used
+ * @param max The maximum number to be generated by the function
+ */
+ uint32_t getRandom(uint64_t* seed,uint32_t max);
} // namespace libtp::tools \ No newline at end of file
diff --git a/source/tools.cpp b/source/tools.cpp
index 42cb205..dd5895b 100644
--- a/source/tools.cpp
+++ b/source/tools.cpp
@@ -133,4 +133,12 @@ namespace libtp::tools
return result;
}
+
+ uint32_t getRandom(uint64_t* seed,uint32_t max){
+ uint64_t z = (*seed += 0x9e3779b97f4a7c15);
+ z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
+ z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
+
+ return (z % max);
+ }
} // namespace libtp::tools \ No newline at end of file