k6 community forum

Can we seed the random number generator?

I’d like to have repeatable ‘randomness’

Is it possible to seed your random number generator so I get repeatable sequences from Math.random()

@ryan After a little investigation, it looks like we do have a randomseed function that can be used. For some reason, it wasn’t documented though. It was introduced in this PR: https://github.com/loadimpact/k6/issues/452

This example is giving predictable results for me, so I trust it works as originally spec’d. Once we have docs, we will share that:

import {randomSeed} from "k6";

export default function() {

randomSeed(123456789);
let rnd = Math.random();
console.log(rnd)
}
2 Likes

Thanks for the answer @mark and kudos to whichever engineer realised this would be something useful!