Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad argument to randomseed #161

Open
ncul777 opened this issue Feb 14, 2024 · 0 comments
Open

Bad argument to randomseed #161

ncul777 opened this issue Feb 14, 2024 · 0 comments

Comments

@ncul777
Copy link

ncul777 commented Feb 14, 2024

I'm developing some lua code on OpenWrt 22.03 (latest for my device) which has Lua 5.1.5. I downloaded the luaunit.lua (version 3.4) file to my device, but when running I got the error

luaunit.lua:247: bad argument #1 to 'randomseed' (integer expected, got number)

It seems that the line below returns a number that is bigger than a 32 bit signed integer:
math.floor(os.clock()*1E11)

The initial value of the os.clock() is several hundred ms e.g. 0.07.
Suggestion - use modulus to force range within 32 bit range (and this worked for me)
math.floor((os.clock()*1E11) % 2147483647)

I noticed there was a related PR here

OpenWRT details
root@host:~# cat /etc/openwrt_release DISTRIB_ID='OpenWrt' DISTRIB_RELEASE='22.03.4' DISTRIB_REVISION='r20123-38ccc47687' DISTRIB_TARGET='ath79/nand' DISTRIB_ARCH='mips_24kc' DISTRIB_DESCRIPTION='OpenWrt 22.03.4 r20123-38ccc47687' DISTRIB_TAINTS='busybox'

Lua details
root@host:~# lua -v Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio (double int32)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant