Jump to content

How ZombRand() works.


Recommended Posts

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....end

n == 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 do

foo = ZombRand(n)+1;

Special Cases

  1. ZombRand(0) is always 0
  2. ZombRand(-n) = -1*ZombRand(n)

 

Hope that clears some things up!

Link to comment
Share on other sites

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
×
×
  • Create New...