Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d5f22ec
Update dependencies and attempt a fix for newer versions of webpack
rawr51919 Sep 12, 2023
fd90db0
Update dependencies further and allow npm installs to finally work again
rawr51919 Sep 12, 2023
506ea37
another npm install meme
rawr51919 Sep 12, 2023
496a0dd
npm install fixed for good
rawr51919 Sep 12, 2023
8730332
unnecessary ^ removals reverted
rawr51919 Sep 12, 2023
b325867
add lock file for bun (https://bun.sh)
rawr51919 Sep 12, 2023
a71a158
remove unnecessary packages
rawr51919 Sep 12, 2023
451b791
fix the last of the critical problems
rawr51919 Sep 12, 2023
2e45fe1
Create dependabot.yml
rawr51919 Sep 12, 2023
093f7b1
typo fixed in README, lock files removed from package, and min/max co…
rawr51919 Sep 19, 2023
5b69d41
Merge branch 'master' of https://github.com/rawr51919/random-js
rawr51919 Sep 19, 2023
628e9f6
Add changes from various PRs to docs
rawr51919 Jan 23, 2024
91e1460
enable automerge
rawr51919 Apr 21, 2024
f521ff6
Big update, lots has happened in here!
rawr51919 Aug 12, 2025
c68189c
Fix tslint and fix markdownlint's config file
rawr51919 Aug 12, 2025
7d1208d
Condense build steps as prepublish is already ran after deps install
rawr51919 Aug 12, 2025
9b4775b
Moved the linting to ESLint and converted the Jest config to ESM
rawr51919 Aug 12, 2025
3aad6d6
Add information on why randomInt() is biased based on Summer's own co…
rawr51919 Aug 12, 2025
aa5bab6
Baseline document for adding new RNG engines to `random-js` added
rawr51919 Aug 12, 2025
0a27e29
Added documentation on replicating `Math.random()` in this library
rawr51919 Aug 12, 2025
93fb8ea
Add React Native documentation on Webpack 5+ polyfills (checks off th…
rawr51919 Aug 12, 2025
0565129
fix the last of the warnings
rawr51919 Aug 12, 2025
cb1c54a
readd yarn.lock
rawr51919 Aug 12, 2025
667cd93
add bun.lock, update yarn.lock
rawr51919 Aug 12, 2025
a626c4f
Update the Build Status in the README to GitHub Actions too
rawr51919 Aug 13, 2025
95b9770
Fix JS Markdown for `Math.random()` recreation
rawr51919 Aug 13, 2025
3113ec4
Fix typo in README
rawr51919 Aug 13, 2025
314aed5
Add xorgens-4096 mention in readme
rawr51919 Aug 13, 2025
128c2d7
fix typo in new 'adding RNG engines' document
rawr51919 Aug 13, 2025
9b1acb3
add editorconfig
rawr51919 Aug 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = tab
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
open-pull-requests-limit: 0
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Prepublish CI

on:
push:
branches:
- '**'

jobs:
prepublish:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v5

- name: Setup Node.js 22
uses: actions/setup-node@v4
with:
node-version: '22'

- name: Install dependencies and run prepublish script with npm
run: npm ci
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules
.DS_Store
coverage
.rpt2_cache
dist
dist
4 changes: 4 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"esversion": 6,
"node": true
}
26 changes: 26 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# MD013/line-length - Line length
MD013:
# Number of characters
line_length: 450
# Number of characters for headings
heading_line_length: 450
# Number of characters for code blocks
code_block_line_length: 450
# Include code blocks
code_blocks: true
# Include tables
tables: true
# Include headings
headings: true
# Strict length checking
strict: false
# Stern length checking
stern: false

# MD037/no-space-in-emphasis - Spaces inside emphasis markers
MD037: false

# MD046/code-block-style - Code block style
MD046:
# Block style
style: "consistent"
168 changes: 168 additions & 0 deletions ADDING NEW RNG ENGINES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Creating a New RNG Engine in `random-js`

## Overview

Each RNG (Random Number Generator) engine in `random-js` is implemented as a standalone module located in the `src/engine/` directory. This file contains the engine’s logic, configuration parameters, constructor arguments, and all necessary methods for generating random values compatible with the `random-js` ecosystem.

Adding a new RNG engine allows you to customize how random numbers are generated, whether for performance improvements, cryptographic security, or experimental algorithms.

---

## File Structure and Naming

- Create a new file in the `src/engine/` directory for your engine, named appropriately, e.g., `myEngine.ts`.
- Follow the naming conventions and coding style consistent with existing engines in this folder.
- Your engine module should export the engine as a **named export**.

---

## Implementation Requirements

Your RNG engine module must include:

- A **class or function** that implements the RNG engine.
- A **constructor or initialization function** that accepts parameters such as seeds or options needed to configure the engine.
- A core method (commonly `next()`) that returns a random number, usually a floating-point number in the range `[0, 1]`.

### Example Skeleton (Class-based):

```ts
export class myEngine {
private seed: number;

constructor(seed: number) {
this.seed = seed;
// Initialize internal state here
}

next(): number {
// Return a pseudo-random number between 0 (inclusive) and 1 (exclusive)
return Math.random(); // Replace with your algorithm
}
}
```

### Example Skeleton (Function-based):

```ts
export function myEngine(seed: number) {
// Initialization code

return {
next: () => {
return Math.random(); // Replace with your algorithm
}
};
}
```

---

## Exporting and Importing

- Export your engine as a named export in your engine file, e.g.,

```ts
export class myEngine { /* ... */ }
```

or

```ts
export function myEngine(seed: number) { /* ... */ }
```

- Your engine can then be imported elsewhere using:

```ts
import { myEngine } from 'myEngine';
```

This import statement assumes that the build or module resolution system maps `'myEngine'` to the `src/engine/myEngine.ts` file.

---

## Parameters and Configuration

Clearly document any constructor or function parameters your engine uses:

- **Seed:** Typically a number or array to initialize the RNG state.
- **Options:** Any additional configuration parameters like state size, algorithm variants, etc.

Specify accepted types, value ranges, and default values.

---

## Integration

- After implementing your engine, ensure it is integrated into the package’s engine registry or usage points so it can be instantiated by the random-js API.
- Test the integration with example code to confirm it works as expected.

---

## Adding Tests for Your Engine

Testing is essential to ensure your RNG engine behaves correctly, is reproducible with seeds, and produces values within expected ranges.

### Location of Tests

- Place your test file **in the same folder as your engine**, i.e., alongside `src/engine/myEngine.ts`.
- Use a naming convention like `myEngine.test.ts` or `myEngine.spec.ts`.

### What to Test

- **Seed reproducibility:** Confirm that using the same seed produces the same sequence of outputs.
- **Output range:** Verify all generated values are within the expected range (usually `[0, 1]`).
- **Output distribution (optional):** Basic statistical checks or randomness properties.
- **Error handling:** Confirm your engine handles invalid or edge-case inputs gracefully.

### Example Test Snippet

```ts
import { myEngine } from './myEngine';

describe('myEngine', () => {
test('produces reproducible output for the same seed', () => {
const seed = 12345;
const engine1 = new myEngine(seed);
const engine2 = new myEngine(seed);

expect(engine1.next()).toBe(engine2.next());
expect(engine1.next()).toBe(engine2.next());
});

test('produces numbers in [0, 1)', () => {
const engine = new myEngine(6789);
for (let i = 0; i < 1000; i++) {
const val = engine.next();
expect(val).toBeGreaterThanOrEqual(0);
expect(val).toBeLessThan(1);
}
});
});
```

### Running Tests

- Run tests using the standard project test commands (e.g., `npm test` or `yarn test`).
- Ensure your new tests pass before submitting changes.

---

## Example Usage

```ts
import { myEngine } from 'myEngine';

const engine = new myEngine(12345);
const randomValue = engine.next();
console.log(randomValue); // Outputs a number between 0 and 1
```

---

## Reference Existing Engines

For concrete examples, review existing engines in `src/engine/` such as `MersenneTwister19937.ts` or `nativeMath.ts`. These examples demonstrate handling of state, seeding, and producing random values compatible with the `random-js` system, as well as their corresponding tests.

---
34 changes: 18 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
# 2.1.0 (2019-05-30)
# Changelog

## 2.1.0 (2019-05-30)

- Changed `dist/` outputs:
- `random-js.js` => `random-js.umd.js`
- `random-js.mjs` => `random-js.esm.js`
- `random-js.min.js` => `random-js.umd.min.js`

# 2.0.0 (2019-04-01)
## 2.0.0 (2019-04-01)

- Release 2.0.0 (no code changes from 2.0.0-rc5)

# 2.0.0-rc5 (2019-03-15)
## 2.0.0-rc5 (2019-03-15)

- Add sourcemaps

# 2.0.0-rc4 (2019-03-15)
## 2.0.0-rc4 (2019-03-15)

- Improve minified bundle size
- Add `"sideEffects": false` to `package.json` as a hint to Webpack

# 2.0.0-rc3 (2019-03-10)
## 2.0.0-rc3 (2019-03-10)

- Provide a binding for `try`-`catch` to help parsing issues [#30](https://github.com/ckknight/random-js/issues/30)

# 2.0.0-rc2 (2019-02-20)
## 2.0.0-rc2 (2019-02-20)

- Added `nodeCrypto` engine
- Exposed `createEntropy` function, which can be used when seeding a Mersenne Twister
- Changed `browserCrypto` to no longer be `null` if outside of a browser context, instead `throw`ing on first use.

# 2.0.0-rc1 (2019-02-17)
## 2.0.0-rc1 (2019-02-17)

- Converted to TypeScript, with type definitions available.
- Using ESNext-style modules (though still available as UMD)
Expand All @@ -37,25 +39,25 @@
- Using rollup to package the build
- Changed .travis.yml node versions

# 1.0.8 (2015-10-13)
## 1.0.8 (2015-10-13)

- add `getUseCount()` to the `mt19937` engine, which returns how many requests or discards have occurred.

# 1.0.7 (2015-10-13)
## 1.0.7 (2015-10-13)

- the current time is now used in `Random.generateEntropyArray`

# 1.0.6 (2015-09-28)
## 1.0.6 (2015-09-28)

- removed the optionalDependencies in package.json "benchmark" and "microtime".

# 1.0.5 (2015-03-03)
## 1.0.5 (2015-03-03)

- `sample()` results are no longer biased toward the final element.
- `discard(count)` on the `mt19937` engine properly works when count is less than 625
- Clarify that the built-in engines return signed 32-bit integers (not unsigned).

# 1.0.4 (2014-05-11)
## 1.0.4 (2014-05-11)

- `string('')` now throws an error
- `hex(upper)` now returns a cached function, for efficiency.
Expand All @@ -64,20 +66,20 @@
- add benchmark suite, covers engines, integer, bool, and real.
- add `date(start, end)`, which returns a Date within a uniform distribution.

# 1.0.3 (2014-04-23)
## 1.0.3 (2014-04-23)

- `Random` no longer needs to be called with new, allowing `var r = require('random-js')()`
- Add `begin` and `end` arguments to `pick` and `picker`.

# 1.0.2 (2014-03-20)
## 1.0.2 (2014-03-20)

- Even if `shuffle` receives an empty array, it should return that same array.

# 1.0.1 (2014-03-20)
## 1.0.1 (2014-03-20)

- Fix `sample` and `shuffle` when they are passed an empty array.
- Include `-c` (compress) option when uglifying.

# 1.0.0 (2014-02-16)
## 1.0.0 (2014-02-16)

Initial release
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) Cameron Knight ([email protected])
Copyright (c) Summer Knight ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading