randomint_seeded

INTEGERrandomint_seededINTEGERfromINTEGERtoINTEGERseed

Available in all subroutines.

Identical to randomint, except takes an additional parameter used to seed the random number generator.

This does not use secure random numbers and should not be used for cryptographic purposes.

This function is not prefixed with the std. namespace.

Example

if (randomint_seeded(0, 99, 555) < 5) {
set req.http.X-ABTest = "A";
} else {
set req.http.X-ABTest = "B";
}
if (randomint_seeded(-1, 0, 555) == -1) {
set req.http.X-ABTest = "A";
} else {
set req.http.X-ABTest = "B";
}

Try it out

randomint_seeded is used in the following solution recipes. Recipes apply VCL to real-world use cases and can be deployed as-is, or adapted for your own service. See the full list of recipes for more inspiration.

Click RUN on a sample below to provision a Fastly service, execute the code on Fastly, and see how the function behaves.

A/B testing

Serve different responses to separate user cohorts.