aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorinoas <mail@inoas.com>2022-04-08 23:25:18 +0200
committerLouis Pilfold <louis@lpil.uk>2022-04-16 10:23:34 +0100
commit83c81cc9310667658d7780acadb88592f61edc51 (patch)
treec6d4c326a2909b5627e625ec10db26d5e24f9a04 /src
parent39764618ea7597cf25c294aea1bb227064cef70e (diff)
downloadgleam_stdlib-83c81cc9310667658d7780acadb88592f61edc51.tar.gz
gleam_stdlib-83c81cc9310667658d7780acadb88592f61edc51.zip
fix js
Diffstat (limited to 'src')
-rw-r--r--src/gleam/float.gleam14
-rw-r--r--src/gleam_stdlib.mjs4
2 files changed, 11 insertions, 7 deletions
diff --git a/src/gleam/float.gleam b/src/gleam/float.gleam
index 385d9b4..4c314a9 100644
--- a/src/gleam/float.gleam
+++ b/src/gleam/float.gleam
@@ -321,18 +321,18 @@ fn do_product(numbers: List(Float), initial: Float) -> Float {
}
}
-/// Returns a random seed where 0.0 =< random_seed < 1.0
+/// Returns a random value where 0.0 =< value < 1.0
///
-pub fn random_seed() -> Float {
- do_random_seed()
+pub fn random() -> Float {
+ do_random()
}
if erlang {
+ // Returns a random float uniformly distributed in the value range
// 0.0 =< X < 1.0 and updates the state in the process dictionary.
- /// Returns a random float uniformly distributed in the value range
/// See: <https://www.erlang.org/doc/man/rand.html#uniform-0>
///
- external fn do_random_seed() -> Float =
+ external fn do_random() -> Float =
"rand" "uniform"
}
@@ -344,6 +344,6 @@ if javascript {
/// Note that as numbers in JavaScript are IEEE 754 floating point numbers
/// See: <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random>
///
- external fn do_random_seed() -> Float =
- "math" "random"
+ external fn do_random() -> Float =
+ "../gleam_stdlib.mjs" "random"
}
diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs
index 4dd4aa7..5d80640 100644
--- a/src/gleam_stdlib.mjs
+++ b/src/gleam_stdlib.mjs
@@ -246,6 +246,10 @@ export function power(base, exponent) {
return Math.pow(base, exponent);
}
+export function random() {
+ return Math.random();
+}
+
export function bit_string_slice(bits, position, length) {
let start = Math.min(position, position + length);
let end = Math.max(position, position + length);