Skip to content

Commit

Permalink
Fix for #4
Browse files Browse the repository at this point in the history
  • Loading branch information
selimanac committed Mar 21, 2021
1 parent 2822b61 commit 077b545
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ Testing entropy.

## Release Notes

1.2.5

- Fix for [#4](https://github.com/selimanac/defold-random/issues/4#issue-837151758)

1.2.4

- `rnd.double_range(min, max)` added.
Expand Down
2 changes: 1 addition & 1 deletion game.project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
title = defold-random
version = 1.2.1
version = 1.2.5

[bootstrap]
main_collection = /example/main.collectionc
Expand Down
15 changes: 8 additions & 7 deletions pcgrandom/src/pcgrandom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static int double_range(lua_State *L)
assert(top + 1 == lua_gettop(L));
return 1;
}

static int double_num(lua_State *L)
{
int top = lua_gettop(L);
Expand All @@ -77,7 +78,7 @@ static int roll(lua_State *L)
{
int top = lua_gettop(L);
num = (int)pcg32_boundedrand_r(&rng, 6) + 1;
lua_pushinteger(L, num);
lua_pushnumber(L, num);
assert(top + 1 == lua_gettop(L));
return 1;
}
Expand All @@ -86,20 +87,20 @@ static int toss(lua_State *L)
{
int top = lua_gettop(L);
num = pcg32_boundedrand_r(&rng, 2) ? 0 : 1;
lua_pushinteger(L, num);
lua_pushnumber(L, num);
assert(top + 1 == lua_gettop(L));
return 1;
}

static int range(lua_State *L)
{
int top = lua_gettop(L);
min = luaL_checkinteger(L, 1);
max = luaL_checkinteger(L, 2);
min = luaL_checknumber(L, 1);
max = luaL_checknumber(L, 2);

if (min == max)
{
lua_pushinteger(L, min);
lua_pushnumber(L, min);
return 1;
}

Expand All @@ -111,7 +112,7 @@ static int range(lua_State *L)

max++;
num = pcg32_boundedrand_r(&rng, (max - min)) + min;
lua_pushinteger(L, num);
lua_pushnumber(L, num);
assert(top + 1 == lua_gettop(L));
return 1;
}
Expand Down Expand Up @@ -139,7 +140,7 @@ static int number(lua_State *L)
{
int top = lua_gettop(L);
num = pcg32_random_r(&rng);
lua_pushinteger(L, num);
lua_pushnumber(L, num);
assert(top + 1 == lua_gettop(L));
return 1;
}
Expand Down

0 comments on commit 077b545

Please sign in to comment.