Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sogaiu/janet-pcg-random
https://github.com/sogaiu/janet-pcg-random
janet pcg-random prng
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/sogaiu/janet-pcg-random
- Owner: sogaiu
- Created: 2020-07-16T03:44:40.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-06T15:58:08.000Z (5 months ago)
- Last Synced: 2024-08-06T18:51:48.010Z (5 months ago)
- Topics: janet, pcg-random, prng
- Language: C
- Homepage:
- Size: 183 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# janet-pcg-random
[Janet](https://janet-lang.org/) bindings for the [PCG
Random](https://www.pcg-random.org/) pseudo random number generator.## Status
Early stage, expect changes :)
## Installation
```
jpm install https://github.com/sogaiu/janet-pcg-random
```## Usage
Make module available:
```janet
(import pcgrand)
````pcgrand/make` creates a seeded generator instance:
```janet
(pcgrand/make (int/u64 "1") (int/u64 "1"))
# =>```
Use two `int/64` values to seed: the state initializer and sequence
selection constant (stream id).`pcgrand/random` returns a uniformly distributed 32-bit integer:
```janet
(def rng
(pcgrand/make (int/u64 "1") (int/u64 "1")))
# =>(pcgrand/random rng)
# =>
-914190447(:random rng)
# =>
361947764
````pcgrand/boundedrand` returns a uniformly distributed integer, i,
where 0 <= i < bound:```janet
(def rng
(pcgrand/make (int/u64 "1") (int/u64 "1")))
# =>(pcgrand/boundedrand rng 28)
# =>
9(:boundedrand rng 9)
# =>
2
````pcgrand/srandom` seeds a generator using two `int/u64` values in a
manner similar to `pcgrand/make`:```janet
(def rng
(pcgrand/make (int/u64 "1") (int/u64 "1")))
# =>(pcgrand/random rng)
# =>
-914190447(:random rng)
# =>
361947764(pcgrand/srandom rng (int/u64 "1") (int/u64 "1"))
# =>
nil(:random rng)
# =>
-914190447
```## Acknowledgments
* andrewchambers - discussion, sample code
* bakpakin - janet, sample code
* cellularmitosis - documented sample code
* imneme - pcg-random
* pyrmont - documented sample code