Available inall subroutines.

Identical to randombool, except takes an additional parameter, which is 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.


set req.http.my-hmac = digest.hmac_sha256("sekrit", req.http.X-Token);
set req.http.hmac-chopped = regsub(req.http.my-hmac, "^(..........).*$","\1");
if (randombool_seeded(5,100,std.strtol(req.http.hmac-chopped ,16))) {
set req.http.X-Allowed = "true";
} else {
set req.http.X-Allowed = "false";

Try it out

randombool_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.

Flatten the curve of major traffic spikes with a waiting room

A totally stateless solution to hold back new users for a minimum waiting period to smooth out spikes in traffic.