diff options
author | inoas <mail@inoas.com> | 2022-04-12 17:26:12 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-04-16 10:23:34 +0100 |
commit | 0be9d80b95b8bf378021ef6fd441b31cb6fdabec (patch) | |
tree | 330e1dd5f8aeb2f4311505aed11abcbda3214a7f /src | |
parent | c13cc8b423b3ef297edb745b91d2c628d842d263 (diff) | |
download | gleam_stdlib-0be9d80b95b8bf378021ef6fd441b31cb6fdabec.tar.gz gleam_stdlib-0be9d80b95b8bf378021ef6fd441b31cb6fdabec.zip |
cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/float.gleam | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/src/gleam/float.gleam b/src/gleam/float.gleam index c9d367d..5aeec4f 100644 --- a/src/gleam/float.gleam +++ b/src/gleam/float.gleam @@ -349,8 +349,7 @@ if javascript { "../gleam_stdlib.mjs" "random_uniform" } -import gleam/io - +/// Returns 0.0 if boundary_a and boundary_b are equal /// Based on: /// ```javascript /// return Math.random() * (max - min) + min; // The minimum is inclusive and the maximum is exclusive @@ -363,31 +362,14 @@ pub fn random_between(boundary_a: Float, boundary_b: Float) -> Float { a, b if a >. b -> #(b, a) } case min, max { - min, max if min >=. 0.0 && max >. 0.0 -> { - // io.debug("min >=. 0.0 && max >. 0.0 ") - let range = distance(min, max) - random_uniform() *. range +. min - } - min, max if min <. 0.0 && max <=. 0.0 -> { - // io.debug("min <. 0.0 && max <=. 0.0") - let range = distance(min, max) - random_uniform() *. range +. min - } - min, max if min <. 0.0 && max >. 0.0 -> { - // io.debug("min <. 0.0 && max >. 0.0") - let range = distance(min, max) - random_uniform() *. range +. min - } - min, _max if min == max -> { - io.debug("min == max") - min - } + min, _max if min == max -> min + min, max -> random_uniform() *. distance(min, max) +. min } } -/// If 0.0 it will yield `0.0`. -/// If negative, it will yield `-x < 0 ` -/// If positive, it will yield `0 < x ` +/// If boundary is `0.0` this will yield `0.0`. +/// If negative, this will yield `-x < 0 ` +/// If positive, this will yield `0 < x ` /// pub fn random_to(boundary: Float) -> Float { random_uniform() *. boundary |