Permalink
Browse files

documented the new set_random directive in README and also added a te…

…st case for zero number arguments.
  • Loading branch information...
agentzh committed Jun 8, 2011
1 parent af04bad commit 5c4a47f9b045c56ccb8571f749700e11c703fedd
Showing with 30 additions and 0 deletions.
  1. +16 −0 README
  2. +14 −0 t/rand.t
View
16 README
@@ -123,6 +123,17 @@ Synopsis
echo $signature;
}
+ location = /rand {
+ set $from 3;
+ set $to 15;
+ set_random $rand $from $to;
+
+ # or write directly
+ # set_random $rand 3 15;
+
+ echo $rand; # will print a random integer in the range [3, 15]
+ }
+
Description
Every directive provided by this module can be
mixed freely with other nginx rewrite module's
@@ -170,6 +181,11 @@ Directives
set_hmac_sha1 (only enabled when nginx uses openssl, as with ssl support)
+ set_random $res <from> <to>
+ Note that only non-negative numbers in the "from" to "to" argument are allowed.
+ A (psuedo) random number in the range [<from>, <to>] (inclusive) will be assigned
+ to $res. For now, there's no way to configure a custom random generator seed.
+ Behind the scene, it makes use of the standard C function rand().
Caveats
Do not use $arg_XXX or $http_XXX or other special variables defined in
View
@@ -153,3 +153,17 @@ __DATA__
--- error_code: 500
--- SKIP
+
+
+=== TEST 10: zero is fine
+--- config
+ location /rand {
+ set_random $res 0 0;
+
+ echo $res;
+ }
+--- request
+ GET /rand
+--- response_body
+0
+

0 comments on commit 5c4a47f

Please sign in to comment.