22-04-2007, 05:48 PM
Heres a new Rand for you because that one makes me cry:
- Don't need Randomize
- You're working with and returning a variant
- You're making a loop and constantly "hoping it hits", which would freeze for hours if you specify high values with small gaps
- It will go into an infinite loop if you specify the low as higher than the high
- I ran the code Rand(2000000000, 1999999999) compiled with all optimizations ticked... and about 10 minutes later, its still running :lol:
Also, just want to add, stuff like this:
Can be written:
Its faster since what you're doing is taking the extra processing to do floating-point division, then to remove that floating point with the Int(), so \ 4 just does straight integer division (much faster).
Code:
Public Function Rand(ByVal Low As Long, ByVal High As Long) As Long
Rand = Low + ((Rnd * (High - Low)) \ 1)
End Function
- Don't need Randomize
- You're working with and returning a variant
- You're making a loop and constantly "hoping it hits", which would freeze for hours if you specify high values with small gaps
- It will go into an infinite loop if you specify the low as higher than the high
- I ran the code Rand(2000000000, 1999999999) compiled with all optimizations ticked... and about 10 minutes later, its still running :lol:
Also, just want to add, stuff like this:
Code:
(Int(GetPlayerMAGI(index) / 4)
Can be written:
Code:
(GetPlayerMAGI(index) \ 4)
Its faster since what you're doing is taking the extra processing to do floating-point division, then to remove that floating point with the Int(), so \ 4 just does straight integer division (much faster).