0

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!

Tarwin
  • 592
  • 5
  • 11
  • I found the function std.real2integer(), but sadly it's not available in EPEL7 Version 4.0.3 -_- – Tarwin Feb 15 '17 at 09:57

2 Answers2

0

If you are looking for a solution to generate a/b test values, check this solution

Existing integer values that might help: req.xid, now

matheuzzy
  • 472
  • 3
  • 10
  • Well, yeah. But I need more then two groups, a simple "if cond A else B" doesn't cut it. ;-) – Tarwin Feb 14 '17 at 11:02
0

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);
Tarwin
  • 592
  • 5
  • 11