aboutsummaryrefslogtreecommitdiff
path: root/src/math.c
diff options
context:
space:
mode:
authorame <[email protected]>2026-06-29 05:48:58 -0500
committerame <[email protected]>2026-06-29 05:48:58 -0500
commit727d3541a122795b405208242e6fdf7f8b5add07 (patch)
treedb049f349f669d37c6bf7d7feea18481a4f8b2d9 /src/math.c
parent4ecdd3c18ccc5d3bcaa82ed720bf28443aa0ca9d (diff)
:detatch fix and math.random
Diffstat (limited to 'src/math.c')
-rw-r--r--src/math.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/math.c b/src/math.c
index 3e36e3b..75cd578 100644
--- a/src/math.c
+++ b/src/math.c
@@ -46,3 +46,20 @@ int l_lcm(lua_State* L){
free(nums);
return 1;
}
+
+int l_random(lua_State* L){
+ size_t min = 1;
+ switch(lua_gettop(L)){
+ case 2:
+ min = lua_tointeger(L, 1);
+ lua_remove(L, 1);
+ case 1:
+ lua_pushinteger(L, (rand() % (lua_tointeger(L, 1) - min + 1)) + min);
+ break;
+ case 0:
+ default:
+ lua_pushnumber(L, (double)rand() / (double)RAND_MAX);
+ }
+
+ return 1;
+}