SandyBeaches Posted July 2, 2015 Share Posted July 2, 2015 ZombRand() is used in many mods to get random numbers. However, many are using it incorrectly, and because it returns a random value, they are not realizing they have a bug. The most common problem I have seen is when code is written similar this;n = ZombRand(2);if n == 2 then....else....endn == 2 will always be false as ZombRand(2) will never return 2, only 0 or 1. What is ZombRand(n)?ZombRand is an exposed implimentation of rand.Int(n) with a couple of changes. What does it do?Given value n, ZombRand will return a pseudo random number from the set of INTEGERS from 0 to n-1 inclusive. Why ask for n if it only gives up to n-1?The n in ZombRand(n) is not the maximum value wanted, but the range of the result wanted.For example, ZombRand(4) can return 0, 1, 2, or 3, which is exactly 4 values. If you desire results from 1 to n just dofoo = ZombRand(n)+1;Special CasesZombRand(0) is always 0 ZombRand(-n) = -1*ZombRand(n) Hope that clears some things up! frootloopers, Thunderator, theCrius and 4 others 7 Link to comment Share on other sites More sharing options...
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