Log In  

so today i made this
use it as you want guys
also maybe it's not token-efficient but
i'll leave it up to you

function randprob_from(l)
    --the function expects an
    --array of tables like these:
    --{p=0.5,v='item name'}

    --a "p" value between 0 and 1
    --and a "v" value.

    --"p" is propability of the
    --"v" value being returned

    local lim=1
    local value=rnd()
    for pos in all(l) do
        highlimit=lim
        lim-=pos.p
        lowlimit=lim
        if value<highlimit
        and value>=lowlimit then
            return pos.v
        end
    end
end

Cart #pipugozape-1 | 2023-05-27 | Code ▽ | Embed ▽ | No License

P#130207 2023-05-27 08:15 ( Edited 2023-05-27 08:16)


[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 06:57:40 | 0.010s | Q:15