Skip to content

Commit

Permalink
feat(stdlibs): add math/rand (gnolang#2455)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
thehowl authored Jun 28, 2024
1 parent f6235fd commit f547d7d
Show file tree
Hide file tree
Showing 44 changed files with 2,463 additions and 372 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs-404-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
go-version: '1.22'

- name: Install dependencies
run: go mod download
Expand All @@ -28,4 +28,4 @@ jobs:
run: make -C docs/ build

- name: Run linter
run: make -C docs/ lint
run: make -C docs/ lint
5 changes: 1 addition & 4 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
fail-fast: false
matrix:
goversion:
- "1.21.x"
- "1.22.x"
runs-on: ubuntu-latest
timeout-minutes: 30
Expand All @@ -36,7 +35,6 @@ jobs:
fail-fast: false
matrix:
goversion:
- "1.21.x"
- "1.22.x"
# unittests: TODO: matrix with contracts
runs-on: ubuntu-latest
Expand All @@ -60,7 +58,6 @@ jobs:
fail-fast: false
matrix:
goversion:
- "1.21.x"
- "1.22.x"
# unittests: TODO: matrix with contracts
runs-on: ubuntu-latest
Expand Down Expand Up @@ -92,4 +89,4 @@ jobs:
# Find all directories containing gno.mod file
find ./examples -name "gno.mod" -execdir go run "$GNO_CMD" mod tidy \;
# Check if there are changes after running gno mod tidy
git diff --exit-code || (echo "Some gno.mod files are not tidy, please run 'make tidy'." && exit 1)
git diff --exit-code || (echo "Some gno.mod files are not tidy, please run 'make tidy'." && exit 1)
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The gno repository is primarily based on Go (Golang) and Gno.

The primary tech stack for working on the repository:

- Go (version 1.21+)
- Go (version 1.22+)
- make (for using Makefile configurations)

It is recommended to work on a Unix environment, as most of the tooling is built around ready-made tools in Unix (WSL2
Expand Down
2 changes: 1 addition & 1 deletion contribs/gnodev/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gnolang/gno/contribs/gnodev

go 1.21
go 1.22

replace github.com/gnolang/gno => ../..

Expand Down
2 changes: 1 addition & 1 deletion contribs/gnofaucet/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gnolang/gno/contribs/gnofaucet

go 1.21
go 1.22

require (
github.com/gnolang/faucet v0.2.1
Expand Down
2 changes: 1 addition & 1 deletion contribs/gnokeykc/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gnolang/gno/contribs/gnokeykc

go 1.21
go 1.22

replace github.com/gnolang/gno => ../..

Expand Down
2 changes: 1 addition & 1 deletion contribs/gnomd/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gnolang/gno/contribs/gnomd

go 1.21
go 1.22

require github.com/MichaelMure/go-term-markdown v0.1.4

Expand Down
16 changes: 8 additions & 8 deletions docs/getting-started/local-setup/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ id: installation
# Installation

## Overview
In this tutorial, you will learn how to set up the Gno development environment
locally, so you can get up and running writing Gno code. You will download and
In this tutorial, you will learn how to set up the Gno development environment
locally, so you can get up and running writing Gno code. You will download and
install all the necessary tooling, and validate that it is correctly configured
to run on your machine.

## Prerequisites
- **Git**
- **`make` (for running Makefiles)**
- **Go 1.21+**
- **Go 1.22+**
- **Go Environment Setup**:
- Make sure `$GOPATH` is well-defined, and `$GOPATH/bin` is added to your `$PATH` variable.
- To do this, you can add the following line to your `.bashrc`, `.zshrc` or other config file:
Expand All @@ -30,7 +30,7 @@ GitHub repository somewhere on disk:
git clone https://github.com/gnolang/gno.git
```

## 2. Installing the required tools
## 2. Installing the required tools

There are three tools that should be used for getting started with Gno development:
- `gno` - the GnoVM binary
Expand All @@ -42,7 +42,7 @@ To install all three tools, simply run the following in the root of the repo:
make install
```

## 3. Verifying installation
## 3. Verifying installation

### `gno`
`gno` provides ample functionality to the user, among which is running,
Expand All @@ -59,7 +59,7 @@ You should get the help output from the command:

![gno help](../../assets/getting-started/local-setup/local-setup/gno-help.gif)

Alternatively, if you don't want to have the binary callable system-wide, you
Alternatively, if you don't want to have the binary callable system-wide, you
can run the binary directly:

```bash
Expand All @@ -68,8 +68,8 @@ go run ./cmd/gno --help
```

### `gnodev`
`gnodev` is the go-to Gno development helper tool - it comes with a built in
Gno.land node, a `gnoweb` server to display the state of your smart contracts
`gnodev` is the go-to Gno development helper tool - it comes with a built in
Gno.land node, a `gnoweb` server to display the state of your smart contracts
(realms), and a watcher system to actively track changes in your code. Read more
about `gnodev` [here](../../gno-tooling/cli/gnodev.md).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ In this tutorial, you will learn how to start a local Gno node and connect to an

- **Git**
- **`make` (for running Makefiles)**
- **Go 1.21+**
- **Go 1.22+**
- **Go Environment Setup**: Ensure you have Go set up as outlined in
the [Go official installation documentation](https://go.dev/doc/install) for your environment

Expand Down Expand Up @@ -107,4 +107,4 @@ gnoland start \

That's it! 🎉

Your new Gno node should be up and running, and syncing block data from the remote chain.
Your new Gno node should be up and running, and syncing block data from the remote chain.
4 changes: 2 additions & 2 deletions docs/gno-infrastructure/validators/setting-up-a-new-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Additionally, you will see the different options you can use to make your Gno in

- **Git**
- **`make` (for running Makefiles)**
- **Go 1.21+**
- **Go 1.22+**
- **Go Environment Setup**: Ensure you have Go set up as outlined in
the [Go official installation documentation](https://go.dev/doc/install) for your environment

Expand Down Expand Up @@ -451,4 +451,4 @@ Genesis block generation happens only once during the lifetime of a Gno chain.
This means that if you specify a balances file using `gnoland start`, and the chain has already started (advanced from
block 0), the specified balance sheet will not be applied.

:::
:::
5 changes: 3 additions & 2 deletions docs/reference/go-gno-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ id: go-gno-compatibility

Generics are currently not implemented.

Note that Gno does not support shadowing of built-in types.
Note that Gno does not support shadowing of built-in types.
While the following built-in typecasting assignment would work in Go, this is not supported in Gno.

```go
Expand Down Expand Up @@ -205,7 +205,7 @@ Legend:
| math/big | `tbd` |
| math/bits | `full` |
| math/cmplx | `tbd` |
| math/rand | `todo` |
| math/rand | `full`[^9] |
| mime | `tbd` |
| mime/multipart | `tbd` |
| mime/quotedprintable | `tbd` |
Expand Down Expand Up @@ -291,6 +291,7 @@ Legend:
determinism. Concurrent functionality (such as `time.Ticker`) is not implemented.
[^8]: `crypto/ed25519` is currently only implemented for `Verify`, which should
still cover a majority of use cases. A full implementation is welcome.
[^9]: `math/rand` in Gno ports over Go's `math/rand/v2`.

## Tooling (`gno` binary)

Expand Down
3 changes: 0 additions & 3 deletions examples/gno.land/p/demo/rand/gno.mod

This file was deleted.

139 changes: 0 additions & 139 deletions examples/gno.land/p/demo/rand/rand.gno

This file was deleted.

Loading

0 comments on commit f547d7d

Please sign in to comment.