aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-06-15 15:43:57 +0100
committergingerBill <bill@gingerbill.org>2024-06-15 15:43:57 +0100
commit149ecafdeff6ff2b579ab1c979c147fd04fe4228 (patch)
tree58645f16c27ca623907d8ab778be958ba96efaaa
parent7ec17ecf98c5151b31f7b0a3e090d6b5a4d12c54 (diff)
Remove the need for `rand` in `core:math/big`
-rw-r--r--core/math/big/helpers.odin10
-rw-r--r--core/math/big/internal.odin10
-rw-r--r--core/math/big/prime.odin8
-rw-r--r--core/math/rand/rand.odin1
4 files changed, 13 insertions, 16 deletions
diff --git a/core/math/big/helpers.odin b/core/math/big/helpers.odin
index 1969fac49..ee09bb2c7 100644
--- a/core/math/big/helpers.odin
+++ b/core/math/big/helpers.odin
@@ -362,11 +362,11 @@ platform_count_lsb :: #force_inline proc(a: $T) -> (count: int)
count_lsb :: proc { int_count_lsb, platform_count_lsb, }
-int_random_digit :: proc(r: ^rnd.Rand = nil) -> (res: DIGIT) {
+int_random_digit :: proc() -> (res: DIGIT) {
when _DIGIT_BITS == 60 { // DIGIT = u64
- return DIGIT(rnd.uint64(r)) & _MASK
+ return DIGIT(rnd.uint64()) & _MASK
} else when _DIGIT_BITS == 28 { // DIGIT = u32
- return DIGIT(rnd.uint32(r)) & _MASK
+ return DIGIT(rnd.uint32()) & _MASK
} else {
panic("Unsupported DIGIT size.")
}
@@ -374,12 +374,12 @@ int_random_digit :: proc(r: ^rnd.Rand = nil) -> (res: DIGIT) {
return 0 // We shouldn't get here.
}
-int_random :: proc(dest: ^Int, bits: int, r: ^rnd.Rand = nil, allocator := context.allocator) -> (err: Error) {
+int_random :: proc(dest: ^Int, bits: int, allocator := context.allocator) -> (err: Error) {
/*
Check that `a` is usable.
*/
assert_if_nil(dest)
- return #force_inline internal_int_random(dest, bits, r, allocator)
+ return #force_inline internal_int_random(dest, bits, allocator)
}
random :: proc { int_random, }
diff --git a/core/math/big/internal.odin b/core/math/big/internal.odin
index 29bdf555c..c9b331e55 100644
--- a/core/math/big/internal.odin
+++ b/core/math/big/internal.odin
@@ -2817,11 +2817,11 @@ internal_platform_count_lsb :: #force_inline proc(a: $T) -> (count: int)
internal_count_lsb :: proc { internal_int_count_lsb, internal_platform_count_lsb, }
-internal_int_random_digit :: proc(r: ^rnd.Rand = nil) -> (res: DIGIT) {
+internal_int_random_digit :: proc() -> (res: DIGIT) {
when _DIGIT_BITS == 60 { // DIGIT = u64
- return DIGIT(rnd.uint64(r)) & _MASK
+ return DIGIT(rnd.uint64()) & _MASK
} else when _DIGIT_BITS == 28 { // DIGIT = u32
- return DIGIT(rnd.uint32(r)) & _MASK
+ return DIGIT(rnd.uint32()) & _MASK
} else {
panic("Unsupported DIGIT size.")
}
@@ -2829,7 +2829,7 @@ internal_int_random_digit :: proc(r: ^rnd.Rand = nil) -> (res: DIGIT) {
return 0 // We shouldn't get here.
}
-internal_int_random :: proc(dest: ^Int, bits: int, r: ^rnd.Rand = nil, allocator := context.allocator) -> (err: Error) {
+internal_int_random :: proc(dest: ^Int, bits: int, allocator := context.allocator) -> (err: Error) {
context.allocator = allocator
bits := bits
@@ -2846,7 +2846,7 @@ internal_int_random :: proc(dest: ^Int, bits: int, r: ^rnd.Rand = nil, allocator
#force_inline internal_grow(dest, digits) or_return
for i := 0; i < digits; i += 1 {
- dest.digit[i] = int_random_digit(r) & _MASK
+ dest.digit[i] = int_random_digit() & _MASK
}
if bits > 0 {
dest.digit[digits - 1] &= ((1 << uint(bits)) - 1)
diff --git a/core/math/big/prime.odin b/core/math/big/prime.odin
index 7fc78c7e5..832c75119 100644
--- a/core/math/big/prime.odin
+++ b/core/math/big/prime.odin
@@ -12,8 +12,6 @@
package math_big
-import rnd "core:math/rand"
-
/*
Determines if an Integer is divisible by one of the _PRIME_TABLE primes.
Returns true if it is, false if not.
@@ -315,7 +313,7 @@ internal_int_prime_miller_rabin :: proc(a, b: ^Int, allocator := context.allocat
Assumes `a` not to be `nil` and to have been initialized.
*/
-internal_int_is_prime :: proc(a: ^Int, miller_rabin_trials := int(-1), miller_rabin_only := USE_MILLER_RABIN_ONLY, r: ^rnd.Rand = nil, allocator := context.allocator) -> (is_prime: bool, err: Error) {
+internal_int_is_prime :: proc(a: ^Int, miller_rabin_trials := int(-1), miller_rabin_only := USE_MILLER_RABIN_ONLY, allocator := context.allocator) -> (is_prime: bool, err: Error) {
context.allocator = allocator
miller_rabin_trials := miller_rabin_trials
@@ -461,7 +459,7 @@ internal_int_is_prime :: proc(a: ^Int, miller_rabin_trials := int(-1), miller_ra
for ix := 0; ix < miller_rabin_trials; ix += 1 {
// rand() guarantees the first digit to be non-zero
- internal_random(b, _DIGIT_TYPE_BITS, r) or_return
+ internal_random(b, _DIGIT_TYPE_BITS) or_return
// Reduce digit before casting because DIGIT might be bigger than
// an unsigned int and "mask" on the other side is most probably not.
@@ -1183,7 +1181,7 @@ internal_int_prime_next_prime :: proc(a: ^Int, trials: int, bbs_style: bool, all
This is possibly the mother of all prime generation functions, muahahahahaha!
*/
-internal_random_prime :: proc(a: ^Int, size_in_bits: int, trials: int, flags := Primality_Flags{}, r: ^rnd.Rand = nil, allocator := context.allocator) -> (err: Error) {
+internal_random_prime :: proc(a: ^Int, size_in_bits: int, trials: int, flags := Primality_Flags{}, allocator := context.allocator) -> (err: Error) {
context.allocator = allocator
flags := flags
trials := trials
diff --git a/core/math/rand/rand.odin b/core/math/rand/rand.odin
index 7bb78cc1d..8e3c0264d 100644
--- a/core/math/rand/rand.odin
+++ b/core/math/rand/rand.odin
@@ -6,7 +6,6 @@ package rand
import "base:intrinsics"
import "base:runtime"
-import "core:crypto"
import "core:math"
import "core:mem"