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

feat(stdlibs): add math/rand #2455

Merged
merged 9 commits into from
Jun 28, 2024
Merged

feat(stdlibs): add math/rand #2455

merged 9 commits into from
Jun 28, 2024

Conversation

thehowl
Copy link
Member

@thehowl thehowl commented Jun 27, 2024

This PR ports over to Gno the math/rand/v2 Go package. It provides pseudo-random number generation.

Notable omissions:

This PR requires a version bump to go 1.22 to have math/rand/v2 in the standard libraries; otherwise the Native tests won't work. We can rollback the changes to move it to 1.22 by removing the native math/rand implementation, and only using the stdlibs.

BREAKING CHANGE: existing usages of math/rand used Go's math/rand; however, in this new standard library we use its v2, so results will be different.

Closes #1272; See-also #1267

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@thehowl
Copy link
Member Author

thehowl commented Jun 27, 2024

cc @leohhhn

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Jun 27, 2024
@thehowl thehowl requested review from jaekwon, deelawn, mvertes, moul and a team as code owners June 27, 2024 18:53
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Jun 27, 2024
Copy link

codecov bot commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.71%. Comparing base (f6235fd) to head (a9f9f47).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2455      +/-   ##
==========================================
+ Coverage   54.68%   54.71%   +0.03%     
==========================================
  Files         583      583              
  Lines       78503    78499       -4     
==========================================
+ Hits        42930    42952      +22     
+ Misses      32364    32341      -23     
+ Partials     3209     3206       -3     
Flag Coverage Δ
contribs/gnodev 23.81% <ø> (ø)
contribs/gnofaucet 14.46% <ø> (ø)
contribs/gnokeykc 0.00% <ø> (ø)
contribs/gnomd 0.00% <ø> (ø)
gno.land 62.54% <ø> (ø)
gnovm 59.98% <100.00%> (+0.03%) ⬆️
misc/autocounterd 0.00% <ø> (ø)
misc/genproto 0.00% <ø> (ø)
misc/genstd 73.90% <ø> (ø)
misc/goscan 0.00% <ø> (ø)
misc/logos 17.38% <ø> (ø)
misc/loop 0.00% <ø> (ø)
tm2 54.46% <ø> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Jun 27, 2024
Copy link
Contributor

@deelawn deelawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I just left a couple comments with questions. It looks like some of the tests are failing; updating references from rand.Intn -> rand.IntN looks like it will fix it.

gnovm/stdlibs/math/rand/rand_test.gno Outdated Show resolved Hide resolved
gnovm/stdlibs/math/rand/rand.gno Show resolved Hide resolved
gnovm/stdlibs/math/rand/rand.gno Show resolved Hide resolved
gnovm/stdlibs/math/rand/rand.gno Show resolved Hide resolved
Copy link
Contributor

@mvertes mvertes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thehowl thehowl merged commit f547d7d into master Jun 28, 2024
113 checks passed
@thehowl thehowl deleted the dev/morgan/math-rand branch June 28, 2024 10:28
moul added a commit to moul/gno that referenced this pull request Jul 3, 2024
gfanton pushed a commit to gfanton/gno that referenced this pull request Jul 23, 2024
This PR ports over to Gno the
[math/rand/v2](https://pkg.go.dev/math/rand/v2) Go package. It provides
pseudo-random number generation.

Notable omissions:

- the [`N` generic function](https://pkg.go.dev/math/rand/v2@go1.22.4#N)
- The [chacha8 random
source](https://pkg.go.dev/math/rand/v2@go1.22.4#ChaCha8) (we can use
PCG instead; and chacha8 can be implemented later)

This PR requires a version bump to go 1.22 to have math/rand/v2 in the
standard libraries; otherwise the Native tests won't work. We can
rollback the changes to move it to 1.22 by removing the native math/rand
implementation, and only using the stdlibs.

BREAKING CHANGE: existing usages of math/rand used Go's math/rand;
however, in this new standard library we use its v2, so results will be
different.

Closes gnolang#1272; See-also gnolang#1267 

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
moul added a commit that referenced this pull request Aug 9, 2024
- Revert partially "feat(stdlibs): add math/rand (#2455)
(f547d7d)
- Update p/demo/rand and rename to p/demo/entropy

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Co-authored-by: Marc Vertes <mvertes@free.fr>
MikaelVallenet pushed a commit to MikaelVallenet/gno that referenced this pull request Aug 17, 2024
- Revert partially "feat(stdlibs): add math/rand (gnolang#2455)
(f547d7d)
- Update p/demo/rand and rename to p/demo/entropy

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Co-authored-by: Marc Vertes <mvertes@free.fr>
linhpn99 pushed a commit to linhpn99/gno that referenced this pull request Aug 20, 2024
- Revert partially "feat(stdlibs): add math/rand (gnolang#2455)
(f547d7d)
- Update p/demo/rand and rename to p/demo/entropy

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Co-authored-by: Marc Vertes <mvertes@free.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Port math/rand to gno
4 participants