Port Math::Random::MT as a bundled Java XS implementation

Open
#2,005 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
45/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
java, perl
Domain
backend, devtools

Research direction

Start by inspecting the bundled Java XS bridge pattern and registry, then read the upstream Math-Random-MT 1.17 tests and implementation to identify the required seeded vectors and API behavior. Add the bridge, Perl shim, and focused project tests; validate those tests with system Perl first. Done means the upstream suite and both named Games-Solitaire-BlackHole-Solver tests pass on JVM and interpreter backends, with no runtime need for MT.xs or _mt.c.

Written by the indexing model from the issue text.

Description

area:cpan-port enhancement

Summary

Add a bundled Java implementation of Math::Random::MT so PerlOnJava can load the CPAN module without its XS binary. This should also unblock CPAN consumers that require Math::Random::MT at runtime, including Games-Solitaire-BlackHole-Solver.

Evidence

CPAN random run 20261109-091152-39587 tested Games-Solitaire-BlackHole-Solver 0.18.0. Under PerlOnJava, t/00-compile.t could not load Math::Random::MT because no Java XS implementation was available; t/01-run.t then failed after the solver could not run. The system-Perl oracle passed the complete target suite: 27/27 tests across both test programs. The same system-Perl run built and passed Math-Random-MT 1.17's nine test files (125 tests).

The failed solver requires Math::Random::MT at runtime. Targeted MetaCPAN reverse-dependency data reports 13 unique released CPAN distributions with runtime dependencies, 4 recent; examples include Games-Solitaire-BlackHole-Solver, Task-BeLike-SHLOMIF, Log-GELF-Util, and Bencher-Scenario-RandomNumbers.

Proposed implementation

Provide the Java XS bridge and Perl shim for the Math::Random::MT API, following the project's existing Java XS bridge pattern. Bouncy Castle is already a project dependency, but its documented RandomGenerator is an interface and does not itself provide an MT19937 engine. Avoid assuming that a Bouncy Castle DRBG has MT19937-compatible sequences. A small pure-Java MT19937 implementation avoids adding another runtime dependency; Apache Commons RNG is an alternative only if its additional dependency and seed/output compatibility are justified.

Preserve the CPAN module's behavior and seeded sequence, including:

  • Object interface: new, set_seed, get_seed, rand, and irand.
  • Functional interface and optional exports: srand, rand, and irand.
  • Single unsigned 32-bit seed and array seeding (up to 624 words), including the published high-value seed cases.
  • Automatic seeding when no seed is supplied, without changing Perl's CORE::rand state beyond the upstream behavior.
  • Unsigned 32-bit results from irand and [0, n) floating-point results from rand(n).

Acceptance criteria

  • Add the module to the bundled Java XS registry and provide the required Perl-facing shim, without modifying upstream CPAN tests.
  • Add project-owned focused tests for seeded MT19937 output, array seeding, unsigned output, OO calls, function imports, and automatic seeding. Validate new Perl unit tests with system Perl first as required by the repository.
  • Run the upstream Math-Random-MT 1.17 suite with the Java implementation and confirm its deterministic vectors match system Perl.
  • Re-run Games-Solitaire-BlackHole-Solver 0.18.0 with PerlOnJava and confirm both t/00-compile.t and t/01-run.t pass; test JVM and interpreter backends.
  • Confirm native MT.xs/_mt.c is not needed at runtime when the Java implementation is selected.

References

Dominant language
Perl
Stars
67
Forks
8
Avg merge
5h 12m
Merged PRs (30d)
131

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fglock/PerlOnJava

All issues in fglock/PerlOnJava

Similar issues

More Perl issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.