Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/raybellis/java-random
A partial implementation of java.util.Random for JavaScript
https://github.com/raybellis/java-random
Last synced: 3 days ago
JSON representation
A partial implementation of java.util.Random for JavaScript
- Host: GitHub
- URL: https://github.com/raybellis/java-random
- Owner: raybellis
- Created: 2018-11-08T07:31:53.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-15T15:31:20.000Z (about 6 years ago)
- Last Synced: 2024-12-06T21:42:21.265Z (20 days ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 10
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
JavaRandom
==========An almost complete implementation in JS of the `java.util.Random` class
from J2SE, designed to so far as possible produce the same output
sequences as the Java original when supplied with the same seed.usage:
let Random = require('java-random');
let rng = new Random(1);
let val = rng.nextInt();The functions implemented with direct equivalents are:
setSeed(seed)
nextInt()
nextInt(bound)
nextBoolean()
nextFloat()
nextDouble()
nextBytes(bytes)
nextGaussian()NB: the seed value supplied in the constructor or via `setSeed` is
limited to a maximum of 52 bits (i.e. `Number.MAX_SAFE_INTEGER`).The functions that return a `Stream` are replaced with JS generator
functions:ints()
ints(streamSize)doubles()
doubles(streamSize)The functions that generate `long` values are only available on JS
platforms that are able to return a 64-bit `BigInt` instead of a
`Number` (e.g Chrome 67+, Node.js 10.4.0+):nextLong()
longs()
longs(streamSize)The functions not implemented are:
ints(randomNumberOrigin, randomNumberBound)
ints(streamSize, randomNumberOrigin, randomNumberBound)
doubles(randomNumberOrigin, randomNumberBound)
doubles(streamSize, randomNumberOrigin, randomNumberBound)
longs(randomNumberOrigin, randomNumberBound)
longs(streamSize, randomNumberOrigin, randomNumberBound)