I’d like to have repeatable ‘randomness’
Is it possible to seed your random number generator so I get repeatable sequences from Math.random()
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: Add JS API to set seed for PRNG · Issue #452 · grafana/k6 · GitHub
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)
}
Thanks for the answer @mark and kudos to whichever engineer realised this would be something useful!