-
Notifications
You must be signed in to change notification settings - Fork 171
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
Add random number generation by mapping rand() to math/rand #819
Conversation
b7ca140
to
9a09ecb
Compare
Codecov Report
@@ Coverage Diff @@
## master #819 +/- ##
==========================================
+ Coverage 81.00% 81.08% +0.07%
==========================================
Files 54 54
Lines 7413 7433 +20
==========================================
+ Hits 6005 6027 +22
+ Misses 1184 1182 -2
Partials 224 224
Continue to review full report at Codecov.
|
15326da
to
137d2e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work! Only need to check arguments' types, otherwise all look good 👍
case 0: | ||
return t.vm.initFloatObject(rand.Float64()) | ||
case 1: | ||
return t.vm.InitIntegerObject(rand.Intn(args[0].Value().(int))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably should check arguments' types first. I think .(int)
will make Go panicking when users pass something like a string.
… using math/rand Co-authored-by: Lara Aydin <ayd.dilara@gmail.com> Co-authored-by: Michael Grosser <michael@grosser.it>
@st0012 Sorry for the late turnaround, could you take a look again? I'd appreciate any tips for a simpler way to do safeguarding given 2 arguments at a time. |
…nd() is a non-integer
@lara thanks for the work, everything looks perfect now :-) Regarding the argument checks, I'm afraid there's no better way to do it atm. We did try adding some helpers to solve the issue, but that didn't work out too well. However, I will open a PR for spiking again in the following days. |
We're using
math/rand
, because when we're later implementingsrand()
, we need it to support seeding, whichcrypto/rand
does not provide.Fixes #810