randombool_seeded

BOOLrandombool_seededINTEGERnumeratorINTEGERdenominatorINTEGERseed

Available in all 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.

Example

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 solution recipes, which show real world use cases. Click RUN to provision a Fastly service, execute the code on Fastly, and see how the function behaves.

Waiting room

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

User contributed notes

We welcome comments that add use cases, ideas, tips, and caveats. All comments will be moderated before publication. To post support questions, visit our support center and we'll find you the help you need.