Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wout/prng.onchain.js
A micro JS implementation of the Mulberry32 seedable pseudorandom number generator.
https://github.com/wout/prng.onchain.js
blockchain javascript microjs mulberry32 onchain prng prng-algorithms random
Last synced: 13 days ago
JSON representation
A micro JS implementation of the Mulberry32 seedable pseudorandom number generator.
- Host: GitHub
- URL: https://github.com/wout/prng.onchain.js
- Owner: wout
- License: mit
- Created: 2022-06-10T08:41:54.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-06-12T07:37:50.000Z (over 2 years ago)
- Last Synced: 2024-11-02T07:06:10.529Z (2 months ago)
- Topics: blockchain, javascript, microjs, mulberry32, onchain, prng, prng-algorithms, random
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# prng.onchain.js
A micro JS implementation (112 bytes) of the Mulberry32 pseudorandom number
generator.This library is intended for use in environments where the available storage
space is very limited; like blockchains for example. Everything is stripped down
to the bare essentials.![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/onchainjs/prng.onchain.js)
## Usage
```js
// Initialize a random generator for a given seed value
let rand = Pr.ng(1234)
rand()
// => 0.07329497812315822
rand()
// => 0.7034119898453355
rand()
// => 0.9028560190927237// Re-initialize to start the same sequence again using the same seed value
rand = Pr.ng(1234)
rand()
// => 0.07329497812315822
rand()
// => 0.7034119898453355
rand()
// => 0.9028560190927237
```## Acknowledgements
This implementation is borrowed from
[here](https://github.com/bryc/code/blob/master/jshash/PRNGs.md) and
[here](https://gist.github.com/blixt/f17b47c62508be59987b).## License
prng.onchain.js is licensed under the terms of the MIT License.