Search code examples
varnishvarnish-vclvarnish-4

Varnish4: need a random integer value


I need a random integer value in Varnish 4.

The std.random() function results in a REAL with three trailing digits.

In VCL: 
set req.http.X-AB-test1 = std.random(1,4) 

Observed result: 
X-AB-test1=3.182 

I would love to find some equivalent to the feature that Fastly offers in its extended VCL: 'randombool()' or even better 'randombool_seeded()'

Thank you!


Solution

  • I solved this by upgrading to Varnish 4.1 and using the function std.real2integer() like this:

    set req.http.AB-monitor = std.real2integer(std.random(1,2), 0);