lua-resty-string icon indicating copy to clipboard operation
lua-resty-string copied to clipboard

Documentation Clarification

Open lordnynex opened this issue 10 years ago • 0 comments

@agentzh

The example documentation for resty.random.bytes() contains a while loop. Is there a situation where resty.random.bytes() can return nil, or is this an error in the documentation?

    local resty_random = require "resty.random"
    local str = require "resty.string"
    local strong_random = resty_random.bytes(16,true)
        -- attempt to generate 16 bytes of
        -- cryptographically strong random data
    while strong_random == nil do
        strong_random = resty_random.bytes(16,true)
    end
    ngx.say("random: ", str.to_hex(strong_random))

lordnynex avatar Feb 09 '15 21:02 lordnynex