diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index 2b2e1280c..c979d9c74 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -297,7 +297,7 @@ macro bool @ok(#expr) @builtin return true; } -macro char[] @to_byte_view(&value) @builtin +macro char[] @as_char_view(&value) @builtin { return ((char*)value)[:$sizeof(*value)]; } diff --git a/lib/std/core/types.c3 b/lib/std/core/types.c3 index 37368fccd..c5575c0fa 100644 --- a/lib/std/core/types.c3 +++ b/lib/std/core/types.c3 @@ -78,7 +78,7 @@ macro bool is_numerical($Type) { var $kind = $Type.kindof; $if $kind == TypeKind.DISTINCT: - return is_numerical($Type.inner); + return is_numerical($typefrom($Type.inner)); $else return $kind == TypeKind.SIGNED_INT || $kind == TypeKind.UNSIGNED_INT || $kind == TypeKind.FLOAT || $kind == TypeKind.VECTOR; diff --git a/lib/std/math/math.random.c3 b/lib/std/math/math.random.c3 index 4dca68db8..ffa42da14 100644 --- a/lib/std/math/math.random.c3 +++ b/lib/std/math/math.random.c3 @@ -76,21 +76,27 @@ fn uint128 Random.next_uint128(&self) /** * @param [&inout] self + * @require types::is_numerical($typeof(seed)) **/ -fn void Random.set_seed(&self, long seed) +macro void Random.seed_random(&self, seed) { - self.fns.seed_fn(self, &&bitcast(seed, char[8])) @inline; + self.fns.seed_fn(self, @as_char_view(seed)) @inline; } /** * @param [&inout] random * @param [in] seed **/ -fn void Random.set_seeds(&random, char[] seed) +fn void Random.set_seed(&random, char[] seed) { random.fns.seed_fn(random, seed); } +fn int Random.next(&random, int max) +{ + return (int)(random.next_double() * max); +} + /** * @param [&inout] self **/ @@ -105,7 +111,6 @@ fn float Random.next_float(&self) return val / (float)(1 << 24); } - fn double Random.next_double(&self) { ulong val = self.next_long() & (1UL << 53 - 1); diff --git a/lib/std/math/random/math.seeder.c3 b/lib/std/math/random/math.seeder.c3 index 38dcb47ac..f7374d0a2 100644 --- a/lib/std/math/random/math.seeder.c3 +++ b/lib/std/math/random/math.seeder.c3 @@ -7,7 +7,7 @@ const MUL_LCG64 @local = 0xd1342543de82ef95; macro make_seed($Type, char[] input) { $Type return_value; - seeder(input, @to_byte_view(return_value)); + seeder(input, @as_char_view(return_value)); return return_value; }