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?

1


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.


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)


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



[Please log in to post a comment]