Package jline.gen

Class MatlabRandom

java.lang.Object
jline.gen.MatlabRandom

public final class MatlabRandom extends Object
MATLAB-faithful random draws for the model generators.

One process-wide MT19937 stream plays the role of MATLAB's global generator: after rng(long) it yields the stream MATLAB yields after rng(seed), so a generator seeded alike builds the same model in MATLAB, Python and the JAR. rand is numpy's random_sample, randi([lo,hi]) is lo-1+ceil((hi-lo+1)*rand) (a degenerate range still consumes a draw) and randperm(n) is the stable sort order of rand(1,n). Checked against MATLAB R2026a on 2026-10-13.

  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    One MATLAB rand draw.
    static double[]
    randfixedsum(int n, double s, double a, double b)
    One column of Roger Stafford's randfixedsum(n,1,s,a,b), transcribed from matlab/lib/thirdparty/randfixedsum.m with its draw order: rand(n-1,1) twice, then rand(n,1) for the permutation.
    static int
    randi(int lo, int hi)
    MATLAB randi([lo, hi]).
    static int[]
    randperm(int n)
    MATLAB randperm(n), returned 0-based.
    static void
    rng(long seed)
    Reseeds the shared stream, as MATLAB rng(seed).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • rng

      public static void rng(long seed)
      Reseeds the shared stream, as MATLAB rng(seed).
    • rand

      public static double rand()
      One MATLAB rand draw.
    • randi

      public static int randi(int lo, int hi)
      MATLAB randi([lo, hi]).
    • randperm

      public static int[] randperm(int n)
      MATLAB randperm(n), returned 0-based.
    • randfixedsum

      public static double[] randfixedsum(int n, double s, double a, double b)
      One column of Roger Stafford's randfixedsum(n,1,s,a,b), transcribed from matlab/lib/thirdparty/randfixedsum.m with its draw order: rand(n-1,1) twice, then rand(n,1) for the permutation.