Skip to content

Commit 58efa5c

Browse files
adhi2714zth
authored andcommitted
Added random_int to Core__Math
1 parent 106a882 commit 58efa5c

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/Core__Math.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ var Constants = {};
55

66
var Int = {};
77

8+
function random_int(min, max) {
9+
return (Math.floor(Math.random() * (max - min | 0)) | 0) + min | 0;
10+
}
11+
812
export {
913
Constants ,
1014
Int ,
15+
random_int ,
1116
}
1217
/* No side effect */

src/Core__Math.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ module Int = {
5757
@val external tan: float => float = "Math.tan"
5858
@val external tanh: float => float = "Math.tanh"
5959
@val external trunc: float => float = "Math.trunc"
60+
61+
let random_int: (int, int) => int = (min, max) =>
62+
floor(random() *. Core__Int.toFloat(max - min))->Core__Float.toInt + min

src/Core__Math.resi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,3 +845,5 @@ Math.trunc(42.84) // 42.0
845845
*/
846846
@val
847847
external trunc: float => float = "Math.trunc"
848+
849+
let random_int: (int, int) => int

0 commit comments

Comments
 (0)