Commit dfd1a0a6 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Use drand48() for vmod_std.random().

Seed the RAND48 generator when we seed the RANDOM generator.

This eats up one random number, so test-cases relying on order
needs to shift one down.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5575 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent f5f5ab99
......@@ -1297,6 +1297,7 @@ cli_debug_srandom(struct cli *cli, const char * const *av, void *priv)
if (av[2] != NULL)
seed = strtoul(av[2], NULL, 0);
srandom(seed);
srand48(random());
cli_out(cli, "Random(3) seeded with %lu", seed);
}
......@@ -1317,6 +1318,7 @@ CNT_Init(void)
{
srandomdev();
srand48(random());
xids = random();
CLI_AddFuncs(debug_cmds);
}
......
......@@ -28,10 +28,10 @@ varnish v1 -cliok "debug.srandom 1"
client c1 {
txreq
rxresp
expect resp.http.rnd1 == 0.420
expect resp.http.rnd2 == 1.972
expect resp.http.rnd3 == 8.783
expect resp.http.rnd4 == 99.399
expect resp.http.rnd1 == 0.388
expect resp.http.rnd2 == 7.478
expect resp.http.rnd3 == 9.034
expect resp.http.rnd4 == 99.502
expect resp.bodylen == 9
} -run
......
......@@ -15,6 +15,8 @@ server s2 {
txresp -body "22"
rxreq
txresp -body "22"
rxreq
txresp -body "22"
} -start
server s3 {
rxreq
......@@ -29,8 +31,6 @@ server s4 {
txresp -body "4444"
rxreq
txresp -body "4444"
rxreq
txresp -body "4444"
} -start
varnish v1 -vcl+backend {
......@@ -53,9 +53,6 @@ varnish v1 -vcl+backend {
varnish v1 -cliok "debug.srandom 1"
client c1 {
txreq
rxresp
expect resp.bodylen == 4
txreq
rxresp
expect resp.bodylen == 2
......@@ -83,4 +80,7 @@ client c1 {
txreq
rxresp
expect resp.bodylen == 3
txreq
rxresp
expect resp.bodylen == 2
} -run
......@@ -129,7 +129,7 @@ vmod_random(struct sess *sp, double lo, double hi)
(void)sp;
a = random() / (double)(1ULL<<32);
a = drand48();
a *= hi - lo;
a += lo;
return (a);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment