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.

Even though integer values in VCL are typically 64-bit signed integers, this VCL function only accepts from, to, and seed, which are signed 32-bit integers. The range of valid values for from, to, and seed is therefore −(231) to 231 − 1 inclusive. That is, the minimum and maximum values are -2147483648 and 2147483647 respectively, or -0x80000000 and 0x7FFFFFFF in hexadecimal.

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 code examples. Examples apply VCL to real-world use cases and can be deployed as they are, or adapted for your own service. See the full list of code examples 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.