Generating uniform random numbers in Lua

前端 未结 4 1082
后悔当初
后悔当初 2020-12-01 16:07

I am working on programming a Markov chain in Lua, and one element of this requires me to uniformly generate random numbers. Here is a simplified example to illustrate my qu

4条回答
  •  醉话见心
    2020-12-01 17:02

    There's the Luaossl library solution: (https://github.com/wahern/luaossl)

    local rand = require "openssl.rand"
    local randominteger
    if rand.ready() then -- rand has been properly seeded
        -- Returns a cryptographically strong uniform random integer in the interval [0, n−1].
        randominteger = rand.uniform(99) + 1 -- randomizes an integer from range 1 to 100
    end
    

    http://25thandclement.com/~william/projects/luaossl.pdf

提交回复
热议问题