I am now using this Matlab script to create a sequence of random numbers:
clear all
rng(1234);
N=1000;
vec=randn(1,N);
filename = 'test/randn.mat';
save(filename, 'vec')
And this code to create a file based pseudo-random number generator in Julia:
# Copyright (c) 2025 Uwe Fechner
# SPDX-License-Identifier: BSD-3-Clause
using FLORIDyn
using Test
using LinearAlgebra
using MAT
using Random
if basename(pwd()) == "test"
cd("..")
end
filename="test/randn.mat"
randn_vec=vec(matread(filename)["vec"])
mutable struct FileRNG <: AbstractRNG
const data::Vector{Float64}
idx::Int
end
FileRNG(data::Vector{Float64}) = FileRNG(data, 1)
function Base.rand(rng::FileRNG)
x = rng.data[rng.idx]
rng.idx += 1
return x
end
function Base.rand(rng::FileRNG, ::Type{Float64})
return rand(rng)
end
function Base.rand(rng::FileRNG, ::Type{T}) where {T}
error("FileRNG only supports Float64")
end
Random.randn(rng::FileRNG) = rand(rng)
rng = FileRNG(randn_vec)
FLORIDyn.set_rng(rng)
include("test_windfield.jl")
In my package I defined:
# global variables
RNG::AbstractRNG = Random.default_rng()
function set_rng(rng)
global RNG
RNG = rng
end
This means, normally the default RNG is used, but for the unit tests the FileRNG is used.