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()

1 Like

@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() {

let rnd = Math.random();

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