aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-05-01 15:30:14 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-05-01 15:30:14 -0400
commit70611c0faaf436eaa01f6a6fd87d0637f74a2e4a (patch)
treedcbf76fc572b9b6f0fb8a0fd63061b43e938c292 /src/stdlib
parentc814131f2e5e09fe514746aa546d8baf90270ece (diff)
Add missing file
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/fpconv_license.txt24
-rw-r--r--src/stdlib/random.h23
2 files changed, 47 insertions, 0 deletions
diff --git a/src/stdlib/fpconv_license.txt b/src/stdlib/fpconv_license.txt
new file mode 100644
index 00000000..7ed9dfad
--- /dev/null
+++ b/src/stdlib/fpconv_license.txt
@@ -0,0 +1,24 @@
+License for: fpconv.c, fpconv.h, powers.h
+Boost Software License - Version 1.0 - August 17th, 2003
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/src/stdlib/random.h b/src/stdlib/random.h
new file mode 100644
index 00000000..861fab56
--- /dev/null
+++ b/src/stdlib/random.h
@@ -0,0 +1,23 @@
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
+#include <stdlib.h>
+static ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
+ (void)flags;
+ arc4random_buf(buf, buflen);
+ return buflen;
+}
+#elif defined(__linux__)
+// Use getrandom()
+# include <sys/random.h>
+#else
+ #error "Unsupported platform for secure random number generation"
+#endif
+
+static int64_t random_range(int64_t low, int64_t high) {
+ uint64_t range = (uint64_t)high - (uint64_t)low + 1;
+ uint64_t min_r = -range % range;
+ uint64_t r;
+ do {
+ getrandom(&r, sizeof(r), 0);
+ } while (r < min_r);
+ return (int64_t)((uint64_t)low + (r % range));
+}