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

Add random number generation by mapping rand() to math/rand #819

Merged
merged 4 commits into from
Mar 21, 2020

Conversation

lara
Copy link
Contributor

@lara lara commented Jan 15, 2020

We're using math/rand, because when we're later implementing srand(), we need it to support seeding, which crypto/rand does not provide.

Fixes #810

@lara lara force-pushed the random-number-gen branch 2 times, most recently from b7ca140 to 9a09ecb Compare January 15, 2020 00:53
@codecov
Copy link

codecov bot commented Jan 15, 2020

Codecov Report

Merging #819 into master will increase coverage by 0.07%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
vm/class.go 86.28% <100.00%> (+0.42%) ⬆️
vm/integer.go 65.03% <0.00%> (+0.65%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a85e262...a7436b1. Read the comment docs.

@lara lara requested review from st0012 and hachi8833 January 15, 2020 00:55
@lara lara force-pushed the random-number-gen branch 2 times, most recently from 15326da to 137d2e9 Compare January 15, 2020 16:32
Copy link
Member

@st0012 st0012 left a 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)))
Copy link
Member

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.

@st0012 st0012 assigned st0012 and lara and unassigned st0012 Jan 16, 2020
@st0012 st0012 added this to the version 0.1.12 milestone Jan 16, 2020
@st0012 st0012 modified the milestones: version 0.1.12, version 0.1.13 Feb 16, 2020
Lara Aydin and others added 2 commits March 17, 2020 12:45
… using math/rand

Co-authored-by: Lara Aydin <ayd.dilara@gmail.com>
Co-authored-by: Michael Grosser <michael@grosser.it>
@lara
Copy link
Contributor Author

lara commented Mar 18, 2020

@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.

@st0012
Copy link
Member

st0012 commented Mar 21, 2020

@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.

@st0012 st0012 merged commit c21b38e into goby-lang:master Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Random numbers
2 participants