Discord
Login
Community
DARK THEME

Can we have a random.range function?

I was programming a game and was trying to work with random numbers and I needed to put them in a range so I looked it up but couldn't find anything so I wrote this.

\random.range = function(minimum, maximum)
return (random.next()*(maximum-minimum))+minimum
end

This seems Like a pretty basic thing to make but would save a lot of time @gilles could you possibly integrate this in the next version?

That seems like a good idea. I'll check if I can make it.

Hi! So a user by the name of Mythril made just the function you want! I have been using it for a while now and it works as intended.

Here it is:

 //Random int in a range
 random.intInRange = function(MIN,MAX)
   return floor(random.next() * (floor(MAX) - ceil(MIN) + 1) + ceil(MIN))
 end

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community