Log In  

Is there anyway to set a minimum number for the RND() function so that you can set a range (min to max) instead of the default 0 to max?

P#34711 2017-01-02 01:45 ( Edited 2017-01-03 23:56)

flatline, I think you've got to randomize the range and then adjust for your min.

ie. RND(10)+10 to get something between 10 and 20.

P#34713 2017-01-02 02:15 ( Edited 2017-01-02 07:15)

I've been using these:

-- range
function rndr(a,b) -- min,max
 if (a>b) a,b=b,a -- sanity check
    return a+rnd(b-a)
end

-- around a value
function rnda(c,r) -- center, radius
    r=abs(r) -- sanity check
    return c-r+rnd(2*r)
end

you can remove the sanity checks for better performance if you have full control on the parameters
(calling rnd() with a negative number seems to yield a full range number, from -32768 to 32767)

P#34731 2017-01-02 07:57 ( Edited 2017-01-02 12:57)

Thanks for the help. I figured a function would have to be written and both of those work.

P#34882 2017-01-03 18:56 ( Edited 2017-01-03 23:56)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 07:14:38 | 0.006s | Q:14