Jump to content

math.random exclusions?


Recommended Posts

Posted

You'd need to make a new function for it. Something like:

-- Usage:  math.randomEx( 1, 10, 2,3,4,5,6 )
function math.randomEx( min, max, ... )
local bExcluded;
local iNum;
repeat
math.randomseed( getTickCount( ) );
       bExcluded = false;
       iNum = math.random( min, max );
for _, iVal in ipairs( arg ) do
if iNum == iVal then
               bExcluded = true;
break;
end
end
until not bExcluded;
return iNum;
end

NOT TESTED but should work.

Posted

Or you can use tables:

possible_values = {17,18,19,20,23,24,25}
random_value = possible_values[math.random(#possible_values)]

Posted
Or you can use tables:
possible_values = {17,18,19,20,23,24,25}
random_value = possible_values[math.random(#possible_values)]

I think he wan't "impossible" values, like 50p scripted.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...