Blackvein Posted July 26, 2010 Share Posted July 26, 2010 Just wondering if theres a way to use math.random, and exclude certain values. Example: (math.random 17,25 excluding 21 and 22) Can anyone help? Link to comment
50p Posted July 26, 2010 Share Posted July 26, 2010 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. Link to comment
DiSaMe Posted July 27, 2010 Share Posted July 27, 2010 Or you can use tables: possible_values = {17,18,19,20,23,24,25} random_value = possible_values[math.random(#possible_values)] Link to comment
CrazyDude Posted July 27, 2010 Share Posted July 27, 2010 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now