I have written a simulation in Rust which was previously written in Julia. I need to make sure that the results confirm; the simulation relies heavily on random numbers. I don't want to use any brute-force methods (such as averaging over a big number of runs); I'd rather make sure that the sequence of the random numbers is the same in both languages when using the same seed and the same RNG method.
To start with, I wrote a small piece of code to test generating the random numbers (Julia version 1.11.6 and rustc version 1.89.0):
Julia:
using Random, Printf
const SEED = 0xDEADBEEF
rng = Xoshiro(SEED)
xs = rand(rng, Float64, 100)
for x in xs
@printf("%.17f\n", x)
end
and Rust:
use rand::{Rng, SeedableRng};
use rand_xoshiro::Xoshiro256PlusPlus;
const STATIC_SEED :u64 =0xDEADBEEF;
fn main() {
let mut rng = Xoshiro256PlusPlus::seed_from_u64(STATIC_SEED);
for _ in 0..100 {
let x: f64 = rng.random::<f64>();
println!("{:.17}", x);
}
}
My Rust Cargo.toml looks like this:
[package]
name = "xoshiro_match"
version = "0.1.0"
edition = "2024"
[dependencies]
rand = "0.9.2"
rand_xoshiro = "0.7.0"
However, these produce a completely different set of numbers! Did I miss something, or is there a fundamental problem with this approach?